browserAction.setBadgeText()

Sets the badge text for the browser action. The badge is displayed on top of the icon.

Tabs without a specific badge text will inherit the global badge text, which is "" by default.

Syntax

js
browser.browserAction.setBadgeText(
  details // object
)

This API is also available as chrome.browserAction.setBadgeText().

Parameters

details

An object with the following properties:

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

tabId Optional

integer. Set the badge text only for the given tab. The text is reset when the user navigates this tab to a new page.

windowId Optional

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.

Examples

Add a badge indicating how many times the user clicked the button:

js
let clicks = 0;

function increment() {
  browser.browserAction.setBadgeText({ text: (++clicks).toString() });
}

browser.browserAction.onClicked.addListener(increment);

Example extensions

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
setBadgeText
Chrome – Full support
Chrome 4 (Release date: 2010-01-25)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote
footnote Before Firefox 58, tab-specific badge text is not cleared when a new page is loaded.
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote Full support
details.windowId parameter
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 62 (Release date: 2018-09-05)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – Full support
Safari 18 (Release date: 2024-09-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Safari on iOS – Full support
Safari on iOS 18 (Release date: 2024-09-16)
footnote Full support
The text property of the details parameter can be set to null.
Chrome – Full support
Chrome 83 (Release date: 2020-05-19)
footnote Full support
Edge – Full support
Edge 83 (Release date: 2020-05-21)
footnote Full support
Firefox – Full support
Firefox 59 (Release date: 2018-03-13)
footnote Full support
Opera – Full support
Opera 69 (Release date: 2020-06-24)
footnote Full support
Safari – Full support
Safari 18 (Release date: 2024-09-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Safari on iOS – Full support
Safari on iOS 18 (Release date: 2024-09-16)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

Note: This API is based on Chromium's chrome.browserAction API. This documentation is derived from browser_action.json in the Chromium code.