action
Adds a button to the browser's toolbar.
Note: This API is available in Manifest V3 or higher.
A browser action is a button in the browser's toolbar.
You can associate a popup with the button. The popup is specified using HTML, CSS and JavaScript, just like a normal web page. JavaScript running in the popup gets access to all the same WebExtension APIs as your background scripts, but its global context is the popup, not the current page displayed in the browser. To affect web pages you need to communicate with them via messages.
If you specify a popup, it will be shown — and the content will be loaded — when the user clicks the icon. If you do not specify a popup, then when the user clicks the icon an event is dispatched to your extension.
You can define most of a browser action's properties declaratively using the browser_action
key in the manifest.json.
With the action
API, you can:
- use
action.onClicked
to listen for clicks on the icon.
- get and set the icon's properties — icon, title, popup, and so on. You can get and set these globally across all tabs, or for a specific tab by passing the tab ID as an additional argument.
Events
-
action.onClicked
-
Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup.
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
ColorArray |
88 |
88 |
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |
ImageDataType |
88 |
88 |
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |
action |
88 |
88 |
109 |
? |
74 |
16 |
? |
? |
109 |
? |
16 |
? |
disable |
88 |
88 |
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |
enable |
88 |
88 |
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |
getBadgeBackgroundColor |
88 |
88 |
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |
getBadgeText |
88 |
88 |
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |
getBadgeTextColor |
No |
No |
109 |
? |
No |
No |
? |
? |
109 |
? |
No |
? |
getPopup |
88 |
88 |
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |
getTitle |
88 |
88 |
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |
isEnabled |
No |
No |
109 |
? |
No |
No |
? |
? |
109 |
? |
No |
? |
onClicked |
88 |
88 |
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |
openPopup |
88 |
88 |
109User interaction is not required to call this API when the extensions.openPopupWithoutUserGesture.enabled preference is set (bug 1799344).
|
? |
74 |
16 |
? |
? |
109User interaction is not required to call this API when the extensions.openPopupWithoutUserGesture.enabled preference is set (bug 1799344).
|
? |
16 |
? |
setBadgeBackgroundColor |
88 |
88 |
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |
setBadgeText |
88 |
88 |
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |
setBadgeTextColor |
No |
No |
109 |
? |
No |
No |
? |
? |
109 |
? |
No |
? |
setIcon |
88 |
88["This call is not persisted.", "The imageData parameter is not accepted.", "The path parameter is required."]
|
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |
setPopup |
88 |
88 |
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |
setTitle |
88 |
88 |
109 |
? |
74 |
No |
? |
? |
109 |
? |
No |
? |