Hard-Rock
Hard-Rock

Reputation: 31

Chrome extension > contextMenus Api > can not add onclick handler

I am trying to create a chrome extension. Currently I am about to create context menu for my extension, which will do something when I click on it. So, following google documentation i create parent.

chrome.contextMenus.create({title: "bla", id: "parent"});

Then I create child and try to add onclick handler to it.

chrome.contextMenus.create({
  title: "bla bla", 
  parentId: "parent",
  id: "child",
  onclick : function() { alert("bla bla bla") }
});

So, its works fine without onclick, and not works all at when onclick here.

Upvotes: 2

Views: 1785

Answers (1)

abraham
abraham

Reputation: 47833

Event based background pages (persistent=false) have to use chrome.contextMenus.onClicked listeners.

chrome.contextMenus.create({...});
chrome.contextMenus.onClicked.addListener(function(info, tab) {
    alert("bla bla bla");
});

Upvotes: 3

Related Questions