I'm writing a simple Chrome extension and have been reading the documentation on context menus (i.e. right-click menus).
I downloaded the basic example code (found here) and have been running it in my browser. The example provided creates a context menu with some options in it. When one of those options is clicked, some information is logged to the console.
Without changing any of the example code, I was not able to get the console.log()
statements to work. I removed all the extraneous code to create the simplest version possible that recreates the issue.
function genericOnClick(info, tab) {
console.log("something");
alert("something else");
}
var title = "Test 'selection' menu item";
var id = chrome.contextMenus.create({"title": title, "contexts":
["selection"], "onclick": genericOnClick});
The manifest.json is below:
{
"name": "Context Menus Sample",
"description": "Shows some of the features of the Context Menus API",
"version": "0.6",
"permissions": ["contextMenus"],
"background": {
"scripts": ["sample.js"]
},
"manifest_version": 2
}
With the above code in place, right clicking on a selection opens a context menu which has an option "Test 'selection' menu item". Clicking on this menu item will alert "something else", but nothing will appear in the console.
I am getting no errors in the console.
To reiterate, this behavior was not working for me when I downloaded the basic example provided here and ran it making no changes.