Add-ons

browserAction.setBadgeBackgroundColor()

Sets the background color for the badge.

Syntax

browser.browserAction.setBadgeBackgroundColor(
  details // object
)

Parameters

details
object.
color
The color, specified as one of:
  • a string: any CSS <color> value, For example "red", "#FF0000", or "rgb(255,0,0)".
    Use an empty string - "" - to clear the background.
  • a browserAction.ColorArray object.
tabIdOptional
integer. Sets the badge background color only for the given tab.

Browser compatibility

ChromeEdgeFirefoxFirefox for AndroidOpera
Basic support Yes Yes45 No Yes

The default color in Firefox is: [ 217, 0, 0, 255 ].

Examples

A background color that starts off as red, and turns green when the browser action is clicked:

browser.browserAction.setBadgeText({text: "1234"});
browser.browserAction.setBadgeBackgroundColor({color: "red"});

browser.browserAction.onClicked.addListener(()=> {
  browser.browserAction.setBadgeBackgroundColor({color: "green"});
});

Set the badge background color only for the active tab:

browser.browserAction.setBadgeText({text: "1234"});
browser.browserAction.setBadgeBackgroundColor({color: "red"});

browser.browserAction.onClicked.addListener((tab)=> {
  browser.browserAction.setBadgeBackgroundColor({
    color: "green",
    tabId: tab.id
  });
});

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

 Contributors to this page: groovecoder, andymckay-github, wbamberg, Makyen, chrisdavidmills
 Last updated by: groovecoder,