Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/browseraction/setbadgetext/index.md
6554 views
------{{AddonSidebar()}}
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
This API is also available as chrome.browserAction.setBadgeText().
Parameters
details: An object with the following properties:
text:
stringornull. 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
tabIdis specified,nullremoves the tab-specific badge text so that the tab inherits the global badge text. Otherwise it reverts the global badge text to"".If a
windowIdis specified,nullremoves the window-specific badge text so that the tab inherits the global badge text. Otherwise it reverts the global badge text to"".
tabId{{optional_inline}}:
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_inline}}:
integer. Set the badge text for the given window.
If
windowIdandtabIdare both supplied, the function fails.If
windowIdandtabIdare both omitted, the global badge is set.
Browser compatibility
{{Compat}}
Examples
Add a badge indicating how many times the user clicked the button:
{{WebExtExamples}}
Note: This API is based on Chromium's
chrome.browserActionAPI. This documentation is derived frombrowser_action.jsonin the Chromium code.