Movatterモバイル変換


[0]ホーム

URL:


  1. Mozilla
  2. Add-ons
  3. Browser extensions
  4. JavaScript APIs
  5. menus
  6. menus.overrideContext()

menus.overrideContext()

Hide all default Firefox menu items in favor of providing a custom context menu UI.

The overrideContext method will cause the matching menu items from this extension to be shown instead of the default menu. This method should be called from acontextmenu DOM event handler, and only applies to the menu that opens after this event.

This interface requires themenus.overrideContextpermission.

Syntax

js
browser.menus.overrideContext(  contextOptions // object)

Parameters

contextOptions

object. Options for how the context menus will be overridden.

showDefaultsOptional

boolean. Whether to also include default menu items in the menu.

contextOptional

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

bookmarkIdOptional

string. Required when context is'bookmark'. Requires 'bookmark' permission.

tabIdOptional

integer. Required when context is'tab'. Requires 'tabs' permission.

Examples

Open the tab context menu on your custom UI, in this case:

js
document.addEventListener(  "contextmenu",  (event) => {    const foo = event.target.closest(".foo");    if (foo) {      // When the context menu is opened on an element with the foo class      // set the context to "opening a tab context menu".      browser.menus.overrideContext({        context: "tab",        tabId: parseInt(foo.dataset.tabId, 10),      });    }  },  { capture: true },);

Seethis blog post for more details.

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp