browserAction API
The browserAction API first appeared in Thunderbird 64. It is very similar to Firefox’s browserAction API.
Many of our sample extensions use a browserAction.
Important
This API will be replaced in Manifest v3 by the action API.
Use a browserAction to put a button in the mail window toolbar. In addition to its icon, a browserAction button can also have a tooltip, a badge, and a popup. This namespace is called browserAction for compatibility with browser WebExtensions.
Manifest file properties
[browser_action
]
(object)
[browser_style
]
(boolean)
Enable browser styles. See the MDN documentation on browser styles for more information.
[default_area
]
(string)
Defines the location the browserAction button will appear. The default location is maintoolbar.
Supported values:
maintoolbar
tabstoolbar
– [Added in TB 92, backported to TB 91.0.2]
One or more icons for the browserAction button.
[default_label
]
(string)
– [Added in TB 84.0b3, backported to TB 78.6.1]
The label of the browserAction button, defaults to its title. Can be set to an empty string to not display any label. If the containing toolbar is configured to display text only, the title will be used as fallback.
[default_popup
]
(string)
The html document to be opened as a popup when the user clicks on the browserAction button.
[default_title
]
(string)
The title of the browserAction button. This shows up in the tooltip and the label. Defaults to the add-on name.
[default_windows
]
(array of string)
– [Added in TB 106, backported to TB 102.3.3]
Defines the windows, the browserAction should appear in. Defaults to showing it only in the normal Thunderbird window, but can also be shown in the messageDisplay window.
Supported values:
normal
messageDisplay
Specifies dark and light icons to be used with themes. The light
icon is used on dark backgrounds and vice versa. Note: The default theme uses the default_icon
for light backgrounds (if specified).
Functions
setTitle(details)
Sets the title of the browserAction button. Is used as tooltip and as the label of the browserAction button.
Parameters
details
(object)
title
(string or null)
A string the browserAction button should display as its label and when moused over. Cleared by setting it to null or an empty string (title defined the manifest will be used).
[tabId
]
(integer)
Sets the title only for the given tab.
[windowId
]
(integer) Unsupported.
Will throw an error if used.
getTitle(details)
Gets the title of the browserAction button.
Parameters
details
(object)
[tabId
]
(integer)
Specifies for which tab the title should be retrieved. If no tab is specified, the global value is retrieved.
[windowId
]
(integer) Unsupported.
Will throw an error if used.
Return type (Promise)
string
setLabel(details)
– [Added in TB 84.0b3, backported to TB 78.6.1]
Sets the label of the browserAction button. Can be used to set different values for the tooltip (defined by the title) and the label. Additionally, the label can be set to an empty string, not showing any label at all.
Parameters
details
(object)
label
(string or null)
A string the browserAction button should use as its label, overriding the defined title. Can be set to an empty string to not display any label at all. If the containing toolbar is configured to display text only, its title will be used. Cleared by setting it to null.
[tabId
]
(integer)
Sets the label only for the given tab.
[windowId
]
(integer) Unsupported.
Will throw an error if used.
getLabel(details)
– [Added in TB 84.0b3, backported to TB 78.6.1]
Gets the label of the browserAction button.
Parameters
details
(object)
[tabId
]
(integer)
Specifies for which tab the label should be retrieved. If no tab is specified, the global label is retrieved.
[windowId
]
(integer) Unsupported.
Will throw an error if used.
Return type (Promise)
string
setIcon(details)
Sets the icon for the browserAction button. Either the path
or the imageData
property must be specified.
Parameters
details
(object)
The image data for one or more icons for the browserAction button.
The paths to one or more icons for the action button.
[tabId
]
(integer)
Sets the icon only for the given tab.
[windowId
]
(integer) Unsupported.
Will throw an error if used.
setPopup(details)
Sets the html document to be opened as a popup when the user clicks on the browserAction button.
Parameters
details
(object)
popup
(string or null)
The html file to show in a popup. Can be set to an empty string to not open a popup. Cleared by setting it to null (popup value defined the manifest will be used).
[tabId
]
(integer)
Sets the popup only for the given tab.
[windowId
]
(integer) Unsupported.
Will throw an error if used.
getPopup(details)
Gets the html document set as the popup for this browserAction button.
Parameters
details
(object)
[tabId
]
(integer)
Specifies for which tab the popup document should be retrieved. If no tab is specified, the global value is retrieved.
[windowId
]
(integer) Unsupported.
Will throw an error if used.
Return type (Promise)
string
setBadgeText(details)
Sets the badge text for the browserAction button. The badge is displayed on top of the icon.
Parameters
details
(object)
text
(string or null)
Any number of characters can be passed, but only about four can fit in the space. Cleared by setting it to null or an empty string.
[tabId
]
(integer)
Sets the badge text only for the given tab.
[windowId
]
(integer) Unsupported.
Will throw an error if used.
getBadgeText(details)
Gets the badge text of the browserAction button.
Parameters
details
(object)
[tabId
]
(integer)
Specifies for which tab the badge text should be retrieved. If no tab is specified, the global label is retrieved.
[windowId
]
(integer) Unsupported.
Will throw an error if used.
Return type (Promise)
string
setBadgeBackgroundColor(details)
Sets the background color for the badge.
Parameters
details
(object)
The color to use as background in the badge. Cleared by setting it to null or an empty string.
[tabId
]
(integer)
Sets the background color for the badge only for the given tab.
[windowId
]
(integer) Unsupported.
Will throw an error if used.
getBadgeBackgroundColor(details)
Gets the badge background color of the browserAction button.
Parameters
details
(object)
[tabId
]
(integer)
Specifies for which tab the badge background color should be retrieved. If no tab is specified, the global label is retrieved.
[windowId
]
(integer) Unsupported.
Will throw an error if used.
Return type (Promise)
enable([tabId])
Enables the browserAction button for a tab. By default, an browserAction button is enabled.
Parameters
[tabId
]
(integer)
The id of the tab for which you want to modify the browserAction button.
disable([tabId])
Disables the browserAction button for a tab.
Parameters
[tabId
]
(integer)
The id of the tab for which you want to modify the browserAction button.
isEnabled(details)
Checks whether the browserAction button is enabled.
Parameters
details
(object)
[tabId
]
(integer)
Specifies for which tab the state should be retrieved. If no tab is specified, the global value is retrieved.
[windowId
]
(integer) Unsupported.
Will throw an error if used.
Return type (Promise)
boolean
openPopup()
Opens the browserAction’s popup window in the active window.
Events
onClicked
Fired when an browserAction button is clicked. This event will not fire if the browserAction has a popup. This is a user input event handler. For asynchronous listeners some restrictions apply.
Parameters for onClicked.addListener(listener)
listener(tab, info)
A function that will be called when this event occurs.
Parameters passed to the listener function
Types
ColorArray
An array of four integers in the range [0,255] that make up the RGBA color. For example, opaque red is [255, 0, 0, 255].
array of integer
ImageDataDictionary
A dictionary object to specify multiple ImageData objects in different sizes, so the icon does not have to be scaled for a device with a different pixel density. Each entry is a name-value pair with value being an ImageData object, and name its size. Example:
{
"16": icon16,
"32": icon32
}
See the MDN documentation about choosing icon sizes for more information on this.
object
ImageDataType
Pixel data for an image. Must be an ImageData object (for example, from a canvas element).
OnClickData
– [Added in TB 74.0b2]
Information sent when a browserAction button is clicked.
object
modifiers
(array of string)
An array of keyboard modifiers that were held while the menu item was clicked.
Supported values:
Shift
Alt
Command
Only available on macOS.
Ctrl
Not available on macOS.
MacCtrl
Only available on macOS, but of limited use in a click event: Holding down the CTRL key while clicking with the mouse is referred to as a ‘CTRL click’ under macOS and is interpreted as a right mouse click. In a default profile the dom.event.treat_ctrl_click_as_right_click.disabled preference is not enabled and the MacCtrl modifier key is not forwarded to the API.
[button
]
(integer)
An integer value of button by which menu item was clicked.
External Types
The following types are not defined by this API, but by the underlying Mozilla WebExtension code base. They are included here, because there is no other public documentation available.
IconPath
Either a string to specify a relative path of a single icon to be used for all sizes, or a dictionary object to specify paths for multiple icons in different sizes, so the icon does not have to be scaled for a device with a different pixel density. Each entry is a name-value pair with value being a relative path to an icon file, and name its size. Example:
{
"16": "icon16.png",
"32": "icon32.png"
}
See the MDN documentation about choosing icon sizes for more information on this.
ThemeIcons
Define a set of icons for themes depending on whether Thunderbird detects that the theme uses dark or light text. All provided URLs must be relative to the manifest.json file.
object
dark
(string)
A URL pointing to an icon. This icon displays when a theme using dark text is active (such as the Light theme, and the Default theme if no default_icon
is specified).
light
(string)
A URL pointing to an icon. This icon displays when a theme using light text is active (such as the Dark theme).
size
(integer)
The size of the two icons in pixels, for example 16 or 32.