menus.update()

Updates a previously created menu item.

For compatibility with other browsers, Firefox makes this method available via the contextMenus namespace as well as the menus namespace.

This is an asynchronous function that returns a Promise.

Syntax

var updating = browser.menus.update(
  id,               // integer or string
  updateProperties // object
)

Parameters

id
integer or string. The ID of the item to update.
updateProperties
object. The properties to update. The same as the createProperties object passed to menus.create(), except that id and icons can't be set.

Return value

A Promise that will be fulfilled with no arguments if the update was successful, or rejected with an error message if the update failed.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
Basic supportChrome Full support Yes
Alternate Name
Full support Yes
Alternate Name
Alternate Name Uses the non-standard name: contextMenus.update
Edge Full support 14
Alternate Name
Full support 14
Alternate Name
Alternate Name Uses the non-standard name: contextMenus.update
Firefox Full support 55
Full support 55
Full support 48
Alternate Name
Alternate Name Uses the non-standard name: contextMenus.update
Opera Full support Yes
Alternate Name
Full support Yes
Alternate Name
Alternate Name Uses the non-standard name: contextMenus.update
Firefox Android No support No

Legend

Full support  
Full support
No support  
No support
Uses a non-standard name.
Uses a non-standard name.

Examples

This example creates a menu item, then updates its title when the user clicks it:

function onUpdated() {
  console.log("item updated successfully");
}

function onError() {
  console.log("error updating item:" + browser.runtime.lastError);
}

browser.menus.create({
  id: "do-not-click-me",
  title: "Do not click this button",
  contexts: ["all"]
});

browser.menus.onClicked.addListener(function(info, tab) {
  if (info.menuItemId == "do-not-click-me") {
    var updating = browser.contextMenus.update(info.menuItemId, {
      title: "Do not click this button again"
    });
    updating.then(onUpdated, onError);
  }
});

Example extensions

Acknowledgements

This API is based on Chromium's chrome.contextMenus API. This documentation is derived from context_menus.json in the Chromium code.

Document Tags and Contributors

Contributors to this page: JeffersonScher, wbamberg, Makyen
Last updated by: JeffersonScher,