gpt4 book ai didi

Javascript chrome 扩展内容脚本

转载 作者:行者123 更新时间:2023-11-30 12:24:30 24 4
gpt4 key购买 nike

我正在开发一个涉及许多 javascript 脚本的 chrome 扩展。在我的 chrome 扩展 list 中,我试图将脚本设置为在某个 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://*/*"
]
}

谢谢!

最佳答案

语法错误。让我重新缩进您的代码,并附上评论:

"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 格式。第一个片段仅供引用。

关于Javascript chrome 扩展内容脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29928734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com