Add-ons

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

ChromeEdgeFirefoxFirefox for AndroidOpera
Basic support Yes1 Yes1

55

481

No Yes1

1. Supported as contextMenus.update.

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: wbamberg, Makyen
 Last updated by: wbamberg,