Context Menus
For information on how to use experimental APIs, see the chrome.experimental.* APIs page.
Context Menus
The context menus module allows you
to add items to Google Chrome's context menu.
You can choose what types of objects
your context menu additions apply to,
such as images, hyperlinks, and pages.
You can create as many context menu items
as you need, but if more than one
from your extension is visible at once,
Google Chrome automatically collapses them
into a single parent menu.
Manifest
You must declare the "contextMenus" permission
in your extension's manifest to use the API.
Also, you should specify a 16x16-pixel icon
for display next to your menu item.
For example:
{
"name": "My extension",
...
"permissions": [
"contextMenus"
],
"icons": {
"16": "icon-bitty.png",
"48": "icon-small.png",
"128": "icon-large.png"
},
...
}
Examples
You can find samples of this API on the
sample page.
API reference: chrome.contextMenus
Properties
getLastError
chrome.extensionlastError
Methods
create
integer
chrome.contextMenus.create(, object
createProperties, function
callback)
Undocumented.
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 chrome.extension.lastError).
Parameters
-
createProperties
(
optional
enumerated
Type
array of
object
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
type
(
optional
enumerated
Type
array of
string
["normal", "checkbox", "radio", "separator"]
)
-
Undocumented.
- The type of menu item. Defaults to 'normal' if not specified.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
title
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- 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".
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
checked
(
optional
enumerated
Type
array of
boolean
)
-
Undocumented.
- 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.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
contexts
(
optional
enumerated
Type
array of
Type
array of
string
["all", "page", "frame", "selection", "link", "editable", "image", "video", "audio"]
paramType
)
-
Undocumented.
- List of contexts this menu item will appear in. Defaults to ['page'] if not specified.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
onclick
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
- A function that will be called back when the menu item is clicked.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Parameters
-
info
-
Undocumented.
- Information about the item clicked and the context where the click happened.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
tab
(
optional
enumerated
Tab
array of
paramType
)
-
Undocumented.
- The details of the tab where the click took place.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
parentId
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The ID of a parent menu item; this makes the item a child of a previously added item.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
documentUrlPatterns
(
optional
enumerated
Type
array of
Type
array of
string
paramType
)
-
Undocumented.
- 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.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
targetUrlPatterns
(
optional
enumerated
Type
array of
Type
array of
string
paramType
)
-
Undocumented.
- Similar to documentUrlPatterns, but lets you filter based on the src attribute of img/audio/video tags and the href of anchor tags.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
-
-
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
- Called when the item has been created in the browser. If there were any problems creating the item, details will be available in chrome.extension.lastError.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Returns
-
paramName
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The ID of the newly created item.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Callback function
The callback parameter should specify a function
that looks like this:
If you specify the callback parameter, it should
specify a function that looks like this:
function() {...};
This function was added in version .
If you require this function, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
remove
void
chrome.contextMenus.remove(, integer
menuItemId, function
callback)
Undocumented.
Remove a context menu item.
Parameters
-
menuItemId
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The ID of the context menu item to remove.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
- Called when the context menu has been removed.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Returns
Callback function
The callback parameter should specify a function
that looks like this:
If you specify the callback parameter, it should
specify a function that looks like this:
function() {...};
This function was added in version .
If you require this function, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
removeAll
void
chrome.contextMenus.removeAll(, function
callback)
Undocumented.
Remove all context menu items added by this extension.
Parameters
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
- Called when removal is complete.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Returns
Callback function
The callback parameter should specify a function
that looks like this:
If you specify the callback parameter, it should
specify a function that looks like this:
function() {...};
This function was added in version .
If you require this function, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
update
void
chrome.contextMenus.update(, integer
id, object
updateProperties, function
callback)
Undocumented.
Update a previously created context menu item.
Parameters
-
id
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The ID of the item to update.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
updateProperties
(
optional
enumerated
Type
array of
object
)
-
Undocumented.
- The properties to update. Accepts the same values as the create function.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
type
(
optional
enumerated
Type
array of
string
["normal", "checkbox", "radio", "separator"]
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
title
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
checked
(
optional
enumerated
Type
array of
boolean
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
contexts
(
optional
enumerated
Type
array of
Type
array of
string
["all", "page", "frame", "selection", "link", "editable", "image", "video", "audio"]
paramType
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
onclick
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
parentId
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- Note: You cannot change an item to be a child of one of its own descendants.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
documentUrlPatterns
(
optional
enumerated
Type
array of
Type
array of
string
paramType
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
targetUrlPatterns
(
optional
enumerated
Type
array of
Type
array of
string
paramType
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
-
-
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
- Called when the context menu has been updated.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Returns
Callback function
The callback parameter should specify a function
that looks like this:
If you specify the callback parameter, it should
specify a function that looks like this:
function() {...};
This function was added in version .
If you require this function, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
Events
event name
chrome.bookmarksonEvent.addListener(function(Type param1, Type param2) {...});
Undocumented.
A description from the json schema def of the event goes here.
Types
OnClickData
paramName
(
optional
enumerated
Type
array of
object
)
Undocumented.
Information sent when a context menu item is clicked.
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
menuItemId
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The ID of the menu item that was clicked.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
parentMenuItemId
(
optional
enumerated
Type
array of
integer
)
-
Undocumented.
- The parent ID, if any, for the item clicked.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
mediaType
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- One of 'image', 'video', or 'audio' if the context menu was activated on one of these types of elements.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
linkUrl
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- If the element is a link, the URL it points to.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
srcUrl
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- Will be present for elements with a 'src' URL.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
pageUrl
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- The URL of the page where the menu item was clicked.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
frameUrl
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- The URL of the frame of the element where the context menu was clicked, if it was in a frame.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
selectionText
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- The text for the context selection, if any.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
editable
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- A flag indicating whether the element is editable (text input, textarea, etc.).
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-