browserAction.setBadgeText()
Sets the badge text for the browser action. The badge is displayed on top of the icon.
Tabs without an specific badge text will inherit the global badge text, which is ""
by default.
Syntax
browser.browserAction.setBadgeText(
details // object
)
This API is also available as chrome.browserAction.setBadgeText()
.
Parameters
details
object
.text
-
string
ornull
. Any number of characters can be passed, but only about four can fit in the space.Use an empty string -
""
- if you don't want any badge.If a
tabId
is specified,null
removes the tab-specific badge text so that the tab inherits the global badge text. Otherwise it reverts the global badge text to""
.If a
windowId
is specified,null
removes the window-specific badge text so that the tab inherits the global badge text. Otherwise it reverts the global badge text to""
. tabId
Optionalinteger
. Set the badge text only for the given tab. The text is reset when the user navigates this tab to a new page.windowId
Optionalinteger
. Set the badge text for the given window.
- If
windowId
andtabId
are both supplied, the function fails. - If
windowId
andtabId
are both omitted, the global badge is set.
Browser compatibility
Report problems with this compatibility data on GitHubwebextensions-desktop | webextensions-mobile | |||||
---|---|---|---|---|---|---|
setBadgeText | ChromeFull supportYes | EdgeFull support14 | FirefoxFull support45
| OperaFull supportYes | SafariFull support14 | Firefox for AndroidFull support79 |
The text property of the details parameter can be set to null . | ChromeNo supportNo | EdgeNo supportNo | FirefoxFull support59 | OperaNo supportNo | SafariNo supportNo | Firefox for AndroidFull support79 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.
Examples
Add a badge indicating how many times the user clicked the button:
var clicks = 0;
function increment() {
browser.browserAction.setBadgeText({text: (++clicks).toString()});
}
browser.browserAction.onClicked.addListener(increment);
Example extensions
This API is based on Chromium's chrome.browserAction
API. This documentation is derived from browser_action.json
in the Chromium code.
Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.