【发布时间】:2017-07-03 15:46:19
【问题描述】:
我正在尝试为 FireFox 开发一个带有 contextMenu 的 WebExtension。目前我只有两个文件,没有真正的功能。问题是即使使用来自 Mozilla 开发者网络的示例代码,它似乎也不起作用 - 所以我假设它在清单中,但我似乎找不到问题。
这是我的manifest.json 文件:
{
"manifest_version": 2,
"name": "FullWindow",
"version": "1.0",
"description": "Test plugin.",
"permissions": ["contextMenus"],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["fullwindow.js"]
}
]
}
这是我的fullwindow.js 文件:
console.log("Plugin loaded!");
browser.contextMenus.create({
id: "radio-green",
type: "radio",
title: "Make it green",
contexts: ["all"],
checked: false
}, onCreated);
function onCreated() {
if (browser.runtime.lastError) {
console.log("error creating item:" + browser.runtime.lastError);
} else {
console.log("item created successfully");
}
}
console.log("Test!");
这里的问题是除了最初的“插件已加载!”之外,我没有得到任何控制台日志。也不要得到我的上下文菜单。
【问题讨论】:
-
在调试我的插件时,我得到
browser.contextMenus is undefined。同样使用chrome.contextMenus也会出现同样的问题。
标签: javascript firefox-addon-webextensions