contextMenus.update()

Updates a previously created context menu item.

This is an asynchronous function that returns a Promise.

Syntax

var updating = browser.contextMenus.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 contextMenus.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 supportYesYes48NoYes

Examples

This example creates a context 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.contextMenus.create({
  id: "do-not-click-me",
  title: "Do not click this button",
  contexts: ["all"]
});
browser.contextMenus.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.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

Document Tags and Contributors

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