我指的是https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/onClicked。 我已经使用此示例中的代码在我的background-script.js中进行测试,但是这段代码似乎没有像其他webextension代码那样正常工作。
的manifest.json
{
"description": "Description ...",
"manifest_version": 2,
"name": "open-my-page",
"version": "1.0",
"homepage_url": "https://github.com/",
"icons": {
"48": "icons/page-48.png"
},
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_icon": "icons/page-32.png"
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["/content-script.js"]
}],
"permission": [
"activeTab",
"contextMenus",
"notifications",
"tabs",
"<all_urls>"
],
"content_security_policy": "script-src 'self' https://api.github.com; object-src 'self'; img-src 'self'"
}
背景的script.js
console.log('File: background.js');
browser.contextMenus.create({
id: "click-me",
title: "Click me!",
contexts: ["all"]
});
browser.contextMenus.onClicked.addListener((info, tab) => {
console.log("Item " + info.menuItemId + " clicked " +
"in tab " + tab.id);
});
内容-的script.js
console.log('File: content-script.js');
结果:
TypeError: browser.contextMenus is undefined
我正在使用Firefox 52.0.1。
有人有想法吗?
答案 0 :(得分:1)
在manifest.json
文件中,permissions
不是permission
。