读取清单:处理content_script时出错:在WebExtension清单中发现意外的属性

时间:2019-02-13 19:13:19

标签: javascript firefox-webextensions

我正在尝试创建一个简单的firefox插件,该插件将在XHR请求页面后修改页面。不幸的是,加载脚本后,它在about:debugging上显示错误:“正在读取清单:处理content_script时出错:在WebExtension清单中发现了意外的属性。”内容脚本似乎根本不起作用。

试图将match属性更改为content_scripts或在content_scripts内部,但此方法无效

{
"manifest_version": 2,
"name": "Some Name",
"version": "0.01a",
"applications": {
    "gecko": {
        "id": "some id"
    }
},
"description": "Some Description",
"author": "Some Author",
"icons": {
    "48": "icon.png",
    "96": "icon.png"
},
"background": {
    "scripts": ["jquery.min.js","declarations.js","bg.js"]
},
"content_script": [
    {
        "matches": ["*://somewebsite/folder/*"],
        "js": ["jquery.min.js", "content.js"]
    }
],
"permissions": [
    "storage",
    "*://somewebsite/folder/*",
    "webRequest",
    "webRequestBlocking"
]
}

manifest.json有什么问题?错误在哪里?

顺便说一句,content.js:

console.log("CONTENT_SCRIPT");
function someFunction(request, sender, sendresponse) { somecode... }
browser.runtime.onMessage.addListener(someFunction);

第一个是console.log,在调试控制台和Web控制台上都没有显示CONTENT_SCRIPT。

bg.js:

browser.runtime.sendMessage({
        action: "timetodo",
        result: requestDetails
    });

1 个答案:

答案 0 :(得分:1)

问题在于,"content_script"键应为"content_scripts"(如在documentation中所写)。

因此使用:

{
"manifest_version": 2,
"name": "Some Name",
"version": "0.01a",
"applications": {
    "gecko": {
        "id": "some id"
    }
},
"description": "Some Description",
"author": "Some Author",
"icons": {
    "48": "icon.png",
    "96": "icon.png"
},
"background": {
    "scripts": ["jquery.min.js","declarations.js","bg.js"]
},
"content_scripts": [
    {
        "matches": ["*://somewebsite/folder/*"],
        "js": ["jquery.min.js", "content.js"]
    }
],
"permissions": [
    "storage",
    "*://somewebsite/folder/*",
    "webRequest",
    "webRequestBlocking"
]
}