gpt4 book ai didi

javascript - Firefox Webextension - TypeError : browser. contextMenus 未定义

转载 作者:行者123 更新时间:2023-11-29 21:08:04 25 4
gpt4 key购买 nike

我指的是 https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/onClicked .我已使用此示例中的代码在我的 background-script.js 中进行测试,但此代码似乎无法像许多其他 webextension 代码一样正常工作。

list .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'"
}

background-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);
});

content-script.js

console.log('File: content-script.js');

结果:

TypeError: browser.contextMenus is undefined

我使用的是 Firefox 52.0.1。

有人有想法吗?

最佳答案

在您的 manifest.json 文件中,它应该是 permissions 而不是 permission

关于javascript - Firefox Webextension - TypeError : browser. contextMenus 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43003311/

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