i refer https://developer.mozilla.org/en-us/add-ons/webextensions/api/contextmenus/onclicked. have used code in example testing in background-script.js code seems not work other webextension code.
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'" }
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');
result:
typeerror: browser.contextmenus undefined
i'm using firefox 52.0.1.
someone idea?
in manifest.json
file, should permissions
not permission
.
I'm having the same problem. Why aren't the experts providing help for people trying to program Webextensions?
ReplyDelete