Extension Action API: Badge, Icon, Popup, and Tab Scope
How to set toolbar badges, icons, popups, and per-tab action state in Manifest V3 and V2 extension APIs.
This page summarises Chrome’s extension documentation for the action—the control in the browser toolbar (formerly browser action in Manifest V2). You use it to show status on the icon (badge), change the icon, open a popup HTML page on click, and set the tooltip title. The same ideas apply whether you call browser.action (Manifest V3 and cross-browser style) or chrome.browserAction (Manifest V2).
Action API vs browserAction: what name to use
Section titled “Action API vs browserAction: what name to use”In Manifest V3, the unified toolbar control is the action API. In Manifest V2 it was browserAction, with a separate pageAction that only appeared on matching tabs. MV3 merges those patterns into browser.action (and the chrome.action namespace in Chrome).
Sets the badge text for the action. The badge is displayed on top of the icon.
— Chrome, action API
Sets the badge text for the browser action. The badge is displayed on top of the icon.
— Chrome, browserAction
Common conclusion: implement new extensions on browser.action / chrome.action with Manifest V3. Legacy code still uses chrome.browserAction.* with the same badge, icon, popup, and title methods, usually with an optional callback alongside the Promise.
Toolbar badge: text, colors, and readable limits
Section titled “Toolbar badge: text, colors, and readable limits”setBadgeText and getBadgeText: how much text fits on the icon
Section titled “setBadgeText and getBadgeText: how much text fits on the icon”Badge text is the small label drawn on the toolbar icon—for example a count or "!".
Any number of characters can be passed, but only about four can fit in the space. If an empty string (‘’) is passed, the badge text is cleared. If tabId is specified and text is null, the text for the specified tab is cleared and defaults to the global badge text.
— Chrome, action API — setBadgeText
getBadgeText reads the current badge. Without a tab in TabDetails, you get the global (non-tab-specific) text.
Gets the badge text of the action. If no tab is specified, the non-tab-specific badge text is returned. If displayActionCountAsBadgeText is enabled, a placeholder text will be returned unless the declarativeNetRequestFeedback permission is present or tab-specific badge text was provided.
— Chrome, action API — getBadgeText
That last sentence matters when you use declarativeNetRequest to mirror blocked-request counts on the badge (see below).
setBadgeBackgroundColor and setBadgeTextColor
Section titled “setBadgeBackgroundColor and setBadgeTextColor”Background color accepts an RGBA array [0–255] or a CSS color string (for example #FF0000).
An array of four integers in the range [0,255] that make up the RGBA color of the badge. For example, opaque red is [255, 0, 0, 255]. Can also be a string with a CSS value, with opaque red being #FF0000 or #F00.
— Chrome, action API — setBadgeBackgroundColor
For text color (Chrome 110+ on the browser.* surface), you can set color explicitly or omit it:
Not setting this value will cause a color to be automatically chosen that will contrast with the badge’s background color so the text will be visible. Colors with alpha values equivalent to 0 will not be set and will return an error.
— Chrome, action API — setBadgeTextColor
Pair getters getBadgeBackgroundColor and getBadgeTextColor with the setters when you need to persist or debug styling.
declarativeNetRequest: displayActionCountAsBadgeText on the action
Section titled “declarativeNetRequest: displayActionCountAsBadgeText on the action”If your extension blocks or modifies requests with declarativeNetRequest, you can show per-page action counts on the toolbar badge without calling setBadgeText yourself.
Whether to automatically display the action count for a page as the extension’s badge text. This preference is persisted across sessions.
— Chrome, declarativeNetRequest
When this flag is on, getBadgeText may not return the real count unless you hold the declarativeNetRequestFeedback permission or set tab-specific badge text. Plan permissions and your own badge updates accordingly so you do not fight the automatic counter.
setIcon: path, imageData, and pixel density
Section titled “setIcon: path, imageData, and pixel density”setIcon must receive either path or imageData (not neither). You can pass a single asset or a size map for HiDPI displays.
Sets the icon for the action. The icon can be specified either as the path to an image file or as the pixel data from a canvas element, or as dictionary of either one of those. Either the path or the imageData property must be specified.
— Chrome, action API — setIcon
If the icon is specified as a dictionary, the actual image to be used is chosen depending on screen’s pixel density. If the number of image pixels that fit into one screen space unit equals scale, then image with size scale * n will be selected, where n is the size of the icon in the UI.
— Chrome, action API — setIcon parameters
The same density rule appears on declarativeContent SetIcon for rule-driven icon changes. A lone value is treated as the 16 px slot: details.path = foo is equivalent to details.path = {'16': foo}.
Popup and title: click behavior and tooltip
Section titled “Popup and title: click behavior and tooltip”setPopup and getPopup
Section titled “setPopup and getPopup”The popup is a relative path to an HTML file in your extension package. An empty string disables the popup (click may still fire listeners if you use them).
Sets the HTML document to be opened as a popup when the user clicks on the action’s icon.
— Chrome, action API — setPopup
The relative path to the HTML file to show in a popup. If set to the empty string (‘’), no popup is shown.
— Chrome, action API — setPopup parameters
getPopup returns the configured document path for the action (or tab override when scoped).
setTitle and getTitle
Section titled “setTitle and getTitle”The title is the tooltip when the user hovers the toolbar icon.
Sets the title of the action. This shows up in the tooltip.
— Chrome, action API — setTitle
Use tab-specific titles when the action meaning depends on the active page (similar to how MV2 page actions used per-tab setTitle with a required tabId on pageAction).
tabId: per-tab action state that resets on close
Section titled “tabId: per-tab action state that resets on close”Most setters accept an optional tabId. When you use it, the change applies only while that tab is selected; Chrome clears tab-specific state when the tab closes.
Limits the change to when a particular tab is selected. Automatically resets when the tab is closed.
— Chrome, action API — setBadgeText parameters
The same tabId wording appears on setIcon, setPopup, setTitle, and badge color APIs in both action and browserAction. Pattern: global defaults plus tab overrides for context-sensitive UIs.
| Concern | No tabId |
With tabId |
|---|---|---|
| Badge text | Global default for all tabs | Override while that tab is active |
| Icon / popup / title | Default toolbar presentation | Per-tab presentation |
| Lifetime | Until you change it again | Until tab closes or you clear override |
Common mistakes
Section titled “Common mistakes”- Long badge strings — Passing full words or sentences; only about four characters are visible on the badge.
- Fully transparent text color — Alpha
0onsetBadgeTextColoris rejected; use opaque colors or omitcolorfor automatic contrast. - Missing icon source — Calling
setIconwithoutpathorimageDatafails the “at least one image” requirement. - Assuming
getBadgeTextmatches DNR counts — WithdisplayActionCountAsBadgeText, you may see placeholder text unless feedback permission or tab-specific text is set (action — getBadgeText). - MV2 pageAction vs MV3 action — Requiring
tabIdon every pageAction call but forgetting tab scope on MV3 when porting behavior (pageAction vs action).
Related APIs in the same toolbar family (out of scope here)
Section titled “Related APIs in the same toolbar family (out of scope here)”The cluster also touches cookies, identity, sidePanel, webNavigation, and others. Those solve different tasks (storage, OAuth, side UI, frame metadata). Use the action API reference when the user-facing control is the toolbar button itself.
How to check this on your site
Section titled “How to check this on your site”- Load your extension unpacked on
chrome://extensionsand pin the action so the toolbar icon is visible. - In a background or popup script, call
browser.action.setBadgeText({ text: '9' })and confirm the badge renders on the icon; clear withtext: ''per setBadgeText. - Repeat with
tabIdset on two different tabs and switch between them to confirm per-tab overrides and reset after closing a tab (tabId parameter). - If you enable
displayActionCountAsBadgeTextin declarativeNetRequest, comparegetBadgeTextoutput with and withoutdeclarativeNetRequestFeedbackin the manifest. - You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about, and we will correct or clarify it.