contextMenus.create()

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

Syntax

browser.contextMenus.create(
  createProperties, // object
  function() {...}  // optional function
)

Parameters

createProperties
object.
typeOptional
contextMenus.ItemType. The type of menu item. Defaults to 'normal' if not specified.
idOptional
string. The unique ID to assign to this item. Mandatory for event pages. Cannot be the same as another ID for this extension.
titleOptional
string. The text to be displayed in the item; this is required unless type is 'separator'. When the context is 'selection', you can use %s within the string to show the selected text. For example, if this parameter's value is "Translate '%s' to Pig Latin" and the user selects the word "cool", the context menu item for the selection is "Translate 'cool' to Pig Latin".
checkedOptional
boolean. The initial state of a checkbox or radio item: true for selected and false for unselected. Only one radio item can be selected at a time in a given group of radio items.
contextsOptional
array of contextMenus.ContextType. List of contexts this menu item will appear in. Defaults to ['page'] if not specified.
onclickOptional
function. A function that will be called back when the menu item is clicked. Event pages cannot use this; instead, they should register a listener for contextMenus.onClicked.
parentIdOptional
integer or string. The ID of a parent menu item; this makes the item a child of a previously added item.
documentUrlPatternsOptional
array of string. Lets you restrict the item to apply only to documents whose URL matches one of the given patterns. (This applies to frames as well.) For details on the format of a pattern, see match patterns.
targetUrlPatternsOptional
array of string. Similar to documentUrlPatterns, but lets you filter based on the src attribute of img/audio/video tags and the href of anchor tags.
enabledOptional
boolean. Whether this context menu item is enabled or disabled. Defaults to true.
callbackOptional
function. 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.

Return value

integer or string. The ID of the newly created item.

Browser compatibility

EdgeFirefoxChromeOpera
Basic support?45.0Yes33
Firefox
Basic supportNo

Examples

Acknowledgements

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

Document Tags and Contributors

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