开发者

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

开发者 https://www.devze.com 2023-02-01 00:14 出处:网络
I\'m developing a Google Chrome extension th开发者_JAVA百科at makes heavy use of the context menu, and I would like to make certain menu items available only on some domains.

I'm developing a Google Chrome extension th开发者_JAVA百科at 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});


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

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


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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消