Use the browser.menus API to add items to the browser's menus. You can choose what types of objects your context menu additions apply to, such as images, hyperlinks, and pages.

Permissions: menus, menus

_CreateCreateProperties
_CreateCreatePropertiesIcons
_OnShownInfo
_OverrideContextContextOptions
_UpdateUpdateProperties
_UpdateUpdatePropertiesIcons
OnClickData
_ContextType
_CreateCreatePropertiesCommand
_OnClickDataModifiers
_OverrideContextContextOptionsContext
ContextType
ItemType
ACTION_MENU_TOP_LEVEL_LIMIT
onClicked
onHidden
onShown
create
getTargetElement
overrideContext
refresh
remove
removeAll
update
_ContextType:
    | "all"
    | "page"
    | "frame"
    | "selection"
    | "link"
    | "editable"
    | "password"
    | "image"
    | "video"
    | "audio"
    | "launcher"
    | "bookmark"
    | "tab"
    | "tools_menu"
    | "browser_action"
    | "page_action"
    | "action"
_CreateCreatePropertiesCommand:
    | "_execute_browser_action"
    | "_execute_page_action"
    | "_execute_sidebar_action"
    | "_execute_action"
    | "_execute_page_action"
    | "_execute_sidebar_action"
_OnClickDataModifiers: "Shift" | "Alt" | "Command" | "Ctrl" | "MacCtrl"
_OverrideContextContextOptionsContext: "bookmark" | "tab"

ContextType to override, to allow menu items from other extensions in the menu. Currently only 'bookmark' and 'tab' are supported. showDefaults cannot be used with this option.

The different contexts a menu can appear in. Specifying 'all' is equivalent to the combination of all other contexts except for 'tab' and 'tools_menu'.

ItemType: "normal" | "checkbox" | "radio" | "separator"

The type of menu item.

ACTION_MENU_TOP_LEVEL_LIMIT: number

The maximum number of top level extension items that can be added to an extension action context menu. Any items beyond this limit will be ignored.

onClicked: WebExtEvent<(info: browser.menus.OnClickData, tab?: Tab) => void>

Fired when a context menu item is clicked.

Information about the item clicked and the context where the click happened.

The details of the tab where the click took place. If the click did not take place in a tab, this parameter will be missing.

onHidden: WebExtEvent<() => void>

Fired when a menu is hidden. This event is only fired if onShown has fired before.

onShown: WebExtEvent<(info: browser.menus._OnShownInfo, tab: Tab) => void>

Fired when a menu is shown. The extension can add, modify or remove menu items and call menus.refresh() to update the menu.

Information about the context of the menu action and the created menu items. For more information about each property, see OnClickData. The following properties are only set if the extension has host permissions for the given context: linkUrl, linkText, srcUrl, pageUrl, frameUrl, selectionText.

The details of the tab where the menu was opened.

  • Creates a new context menu item. Note that if an error occurs during creation, you may not find out until the creation callback fires (the details will be in runtime.lastError).

    Parameters

    • createProperties: browser.menus._CreateCreateProperties
    • Optionalcallback: () => void

      Called when the item has been created in the browser. If there were any problems creating the item, details will be available in runtime.lastError.

    Returns string | number

    The ID of the newly created item.

  • Retrieve the element that was associated with a recent contextmenu event.

    Parameters

    • targetElementId: number

      The identifier of the clicked element, available as info.targetElementId in the menus.onShown, onClicked or onclick event.

    Returns void | Element

  • Show the matching menu items from this extension instead of the default menu. This should be called during a 'contextmenu' DOM event handler, and only applies to the menu that opens after this event.

    Parameters

    Returns void

  • Updates the extension items in the shown menu, including changes that have been made since the menu was shown. Has no effect if the menu is hidden. Rebuilding a shown menu is an expensive operation, only invoke this method when necessary.

    Returns Promise<any>

  • Removes a context menu item.

    Parameters

    • menuItemId: string | number

      The ID of the context menu item to remove.

    Returns Promise<void>

  • Removes all context menu items added by this extension.

    Returns Promise<void>

  • Updates a previously created context menu item.

    Parameters

    • id: string | number

      The ID of the item to update.

    • updateProperties: browser.menus._UpdateUpdateProperties

      The properties to update. Accepts the same values as the create function.

    Returns Promise<void>