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

Permissions: contextMenus

_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
onClicked: WebExtEvent<
    (info: browser.contextMenus.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.contextMenus._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.contextMenus._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

  • 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

    Returns Promise<void>