Currently, I am in the process of developing my own Firefox extension and I have encountered an issue with adding a listener to an onclick
event for a context menu item.
manifest.json
{
"manifest_version": 2,
"name": "My extension name",
"version": "1.0",
"description": "My extension description",
"icons": {
"48": "icons/icon.png"
},
"permissions": ["menus"],
"background": {
"scripts": ["index.js"]
}
}
index.js
browser.menus.create({
id: 'my-ext-item',
title: 'Custom ctx item',
contexts: ['selection']
});
browser.menus.onClicked.addListener(function(info, tab) {
console.log("Clicked!");
});
The browser.menus.create()
function seems to be working properly as the new item is appearing in my context menu. However, the issue lies in capturing the click event as it never fires.
I followed the code based on the instructions from MDN Web Docs. This was tested on Firefox 97.0.1 x64
.
What did I do wrong and what should I fix?
PS. I also attempted using the older browser.contextMenus.create
and
browser.contextMenus.onClicked.addListener
but that did not work either.