Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I track whether a context menu item is already created by my Chrome Extension?

There are only four methods for chrome.contextMenus:

create
update
remove
removeAll

I am wondering how do I check whether one menu is already created?

I tried this:

try {
  chrome.contextMenus.update("byname", {});
} catch (e) {
 // doesn't exist
}

But it seems the error cannot be caught (but shown in the console).

Thanks for any kind of tips!

like image 535
AGamePlayer Avatar asked Dec 06 '12 15:12

AGamePlayer


1 Answers

Each chrome.contextMenus.create call returns an unique identifier. Store these identifiers in an array or hash to keep track of them.

like image 93
Rob W Avatar answered Sep 28 '22 03:09

Rob W