我正在开发一个Chrome扩展程序,以便在另一个网页上播放或暂停网页的html5视频,并且需要将content.js注入新打开的标签页,我遇到的问题是新打开的标签页标签有两个content.js副本,一个来自创建时的注入,另一个来自旧选项卡,后者打开了新选项卡,这破坏了程序的逻辑,如果刷新新打开的页面,一切都会正常进行。这意味着刷新页面后,content.js的副本将消失。
这种行为完全破坏了我扩展程序的逻辑,我该如何阻止这种情况的发生? manifest.json中是否有配置可以阻止旧页面将它的content.js传递给新打开的页面?
manifest.json
{
"name": "Video Controler",
"version": "1.0",
"description": "Mute html5 video with shortkey.",
"permissions": ["nativeMessaging", "debugger", "storage", "tabs", "http://*/*", "https://*/"],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"background": {
"scripts": ["background.js"],
"persistent": true
},
"page_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icon/icon16.png",
"32": "icon/icon32.png",
"48": "icon/icon48.png",
"128": "icon/icon128.png"
}
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"css": ["videoInfo.css"],
"js": ["content.js"],
"run_at": "document_start"
}
],
"commands": {
"pause" : {
"suggested_key": {
"mac": "Command+Shift+Z"
},
"description": "Pause video"
}
},
"manifest_version": 2
}