menus.remove()

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

js
let removing = browser.menus.remove(
  menuItemId      // integer or string
)

Parameters

integer or string. The ID of the menu item to remove.

Return value

A Promise that will be fulfilled with no arguments if removal was successful, or rejected with an error message if removal failed (for example, because the item could not be found).

Examples

This extension adds a menu item labeled "Remove me!". If you click the item, the extension removes it.

js
function onRemoved() {
  console.log("item removed successfully");
}

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

browser.menus.create({
  id: "remove-me",
  title: "Remove me!",
  contexts: ["all"],
});

browser.menus.onClicked.addListener((info, tab) => {
  if (info.menuItemId === "remove-me") {
    let removing = browser.menus.remove(info.menuItemId);
    removing.then(onRemoved, onError);
  }
});

Example extensions

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
remove
Chrome – Full support
Chrome 6 (Release date: 2010-09-02)
altname
altname Alternate name: contextMenus.remove
Edge – Full support
Edge 79 (Release date: 2020-01-15)
altname
altname Alternate name: contextMenus.remove
Firefox – Full support
Firefox 48 (Release date: 2016-08-02)
altname
altname Alternate name: contextMenus.remove
Firefox – Full support
Firefox 55 (Release date: 2017-08-08)
footnote
footnote From Firefox 136, an error message is returned when the menu item doesn't exist. Previously, the error was ignored and the promise fulfilled.
Opera – Full support
Opera 15 (Release date: 2013-07-02)
altname
altname Alternate name: contextMenus.remove
Safari – Full support
Safari 14 (Release date: 2020-09-16)
altname
altname Alternate name: contextMenus.remove
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.
Uses a non-standard name
Has more compatibility info.

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