我正在开发涉及许多JavaScript脚本的chrome扩展。在我的Chrome扩展程序清单中,我正在尝试将脚本设置为在某个URL上运行。我有一个URL来处理脚本,但是如果我尝试为另一个javascript文件添加另一个权限,则没有任何反应。我的语法或代码是错误的吗?
{
"name": "test",
"manifest_version": 2,
"version": "1.5",
"browser_action": {"default_icon": "icon_16.png"},
"icons" : {
"128": "icon_128.png", "16": "icon_16.png"},
"description": "test.",
"content_scripts": [
{
"matches": ["*://solecarts.com/monitor/run.html*", "*://www.solecarts.com/monitor/run.html*"],
"js": ["query.js"],
"matches": ["*://solecarts.com/monitor/shopify.html*", "*://www.solecarts.com/monitor/shopify.html*"],
"js": ["shopify.js"]
}
], "permissions": [
"tabs", "*://solecarts.com/*", "*://solecarts.com/*",
"http://*/*",
"https://*/*"
]
}

谢谢!
答案 0 :(得分:2)
语法错误。让我用注释重新缩进你的代码:
"content_scripts": [ // An array
{ // An object inside this array
// Properties of that object
"matches": [
"*://solecarts.com/monitor/run.html*",
"*://www.solecarts.com/monitor/run.html*"
],
"js": ["query.js"],
// Same properties within the same object?
"matches": [
"*://solecarts.com/monitor/shopify.html*",
"*://www.solecarts.com/monitor/shopify.html*"
],
"js": ["shopify.js"]
}
],
相反,它应该是一个包含两个独立对象的数组:
"content_scripts": [
{
"matches": [
"*://solecarts.com/monitor/run.html*",
"*://www.solecarts.com/monitor/run.html*"
],
"js": ["query.js"]
}, {
"matches": [
"*://solecarts.com/monitor/shopify.html*",
"*://www.solecarts.com/monitor/shopify.html*"
],
"js": ["shopify.js"]
}
],
请注意,JSON格式不允许发表评论。第一个片段只是提供信息。
答案 1 :(得分:1)
看起来您需要将两个内容脚本对象彼此分开。试试这个:
{
"name": "test",
"manifest_version": 2,
"version": "1.5",
"browser_action": {"default_icon": "icon_16.png"},
"icons" : {
"128": "icon_128.png",
"16": "icon_16.png"
},
"description": "test.",
"content_scripts": [
{
"matches": [
"*://solecarts.com/monitor/run.html*",
"*://www.solecarts.com/monitor/run.html*"
],
"js": ["query.js"]
},
{
"matches": [
"*://solecarts.com/monitor/shopify.html*",
"*://www.solecarts.com/monitor/shopify.html*"
],
"js": ["shopify.js"]
}
],
"permissions": [
"tabs",
"*://solecarts.com/*",
"*://solecarts.com/*",
"http://*/*",
"https://*/*"
]
}