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 or null. 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 "".

tabIdOptional
integer. Set the badge text only for the given tab. The text is reset when the user navigates this tab to a new page.
windowIdOptional
integer. Set the badge text for the given window.
  • If windowId and tabId are both supplied, the function fails.
  • If windowId and tabId are both omitted, the global badge is set.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
Basic supportChrome Full support YesEdge Full support 14Firefox Full support 45
Full support 45
No support 45 — 58
Notes
Notes Tab-specific badge text is not cleared when a new page is loaded.
Opera Full support YesFirefox Android No support No
The text property of the details parameter can be set to null.Chrome No support NoEdge No support NoFirefox Full support 59Opera No support NoFirefox Android No support No
details.windowIdChrome No support NoEdge No support NoFirefox Full support 62Opera No support NoFirefox Android No support No

Legend

Full support  
Full support
No support  
No support
See implementation notes.
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

Acknowledgements

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.

Document Tags and Contributors

Last updated by: Loirooriol,