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

ChromeEdgeFirefoxFirefox for AndroidOpera
Basic support Yes14

45

45 — 581

No Yes
The text property of the details parameter can be set to null. No No59 No No
details.windowId No No62 No No

1. Tab-specific badge text is not cleared when a new page is loaded.

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,