我在创建Chrome扩展程序时遇到一些问题。该代码会影响Chrome中打开的所有网页,我该如何解决?
我的 manifest.json :
{
"manifest_version": 2,
"name": "Merch Tools 41studio",
"description": "report app",
"version": "1.0",
"background": {
"scripts": ["assets/js/jquery.min.js", "assets/js/background.js"]
},
"browser_action": {
"default_icon": "assets/image/icon.png",
"default_popup": "popup.html"
},
"permissions": ["tabs"],
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["assets/js/jquery.min.js", "assets/js/highcharts.js"]
}]
}
答案 0 :(得分:1)
您需要通过更改matches
中的content_scripts
属性来限制内容脚本运行的域列表。拥有"http://*/*","https://*/*"
表示内容脚本在所有http和https网站上运行。相反,您可以指定要运行扩展程序的网站列表。
{
"manifest_version": 2,
"name": "Merch Tools 41studio",
"description": "report app",
"version": "1.0",
"background": {
"scripts": ["assets/js/jquery.min.js", "assets/js/background.js"]
},
"browser_action": {
"default_icon": "assets/image/icon.png",
"default_popup": "popup.html"
},
"permissions": ["tabs"],
"content_scripts": [{
"matches": ["http:/yoursite.com/*"], // Change this to the sites you want your extension to run on
"js": ["assets/js/jquery.min.js", "assets/js/highcharts.js"]
}]
}