2

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.

1
  • Are you accessing the console of the extension? Commented Sep 5, 2017 at 17:20

1 Answer 1

7

To view the console. It's necessary to inspect the background page. The gif below contains an example of how to do this.

https://i.sstatic.net/sw8d5.gif

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.