Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/action/setbadgetext/index.md
6567 views
---
title: action.setBadgeText() slug: Mozilla/Add-ons/WebExtensions/API/action/setBadgeText page-type: webextension-api-function tags: - API - Add-ons - Extensions - Method - Non-standard - Reference - WebExtensions - action - setBadgeText browser-compat: webextensions.api.action.setBadgeText
---

{{AddonSidebar()}}

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

Note: This API is available in Manifest V3 or higher.

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

Syntax

browser.action.setBadgeText( details // object )

This API is also available as chrome.action.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_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 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:

let clicks = 0; function increment() { browser.action.setBadgeText({ text: (++clicks).toString() }); } browser.action.onClicked.addListener(increment);

{{WebExtExamples}}

Browser compatibility

{{Compat}}

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