draeton
draeton

Reputation: 685

Can chrome.contextMenus.update be used to disable a menu item?

I'm developing a Google Chrome extension that makes heavy use of the context menu, and I would like to make certain menu items available only on some domains.

Currently, I am using chrome.tabs.onUpdated and chrome.tabs.onSelectionChanged to check the tab url, and then I add or remove menu items based on a check against a domain list.

Is it possible to just disable the menu items, instead of removing them? I'm hoping for something like this:

chrome.contextMenus.update(id, {"disabled": true});

Upvotes: 2

Views: 3842

Answers (3)

gri fux
gri fux

Reputation: 19

An old post but maybe someone will find this answer useful.

As of Chrome 62 the following works (puts cleaner logic on large context menus): https://developer.chrome.com/apps/contextMenus#method-update

After the menu has been created, update the menu as follows:

chrome.contextMenus.update(intId-or-stringId, {"visible": true});

with toggle:

chrome.contextMenus.update(intId-or-stringId, {"visible": false});

Removing and creating menus will mess the order of the menu (new menus get placed at the bottom). Enabling and disabling still leaves the menu cluttered up. The visible option keeps the original order of the menu intact.

Upvotes: 1

fregante
fregante

Reputation: 31698

It's possible now: https://developer.chrome.com/extensions/contextMenus#property-createProperties-enabled

chrome.contextMenus.update('your-id', {
    enabled: false
});

Upvotes: 3

Mohamed Mansour
Mohamed Mansour

Reputation: 40159

Unfortunately you cannot. That would be a neat feature I suppose. Feel free to submit a feature request http://crbug.com (Make sure you mention any valid use cases for it).

Upvotes: 1

Related Questions