W3cubDocs

/Web Extensions

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

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
setBadgeText
Yes
14
45
45-58
Tab-specific badge text is not cleared when a new page is loaded.
?
Yes
14
?
?
79
?
?
?
null
No
No
59
?
No
No
?
?
79
?
?
?

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

Note: 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.

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/browserAction/setBadgeText