I refer to https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/onClicked. I have used the code in this example for testing in my background-script.js but this code seems not to work properly like so much 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 is undefined
I'm using Firefox 52.0.1.
Someone an idea?
chrome.contextMenus
? Does that one work? – Cunning