Documentation: Chrome Action API
A unified, promise-based wrapper around the Chrome Action API. It transparently uses chrome.action on Manifest V3 and falls back to chrome.browserAction on Manifest V2.
- isAvailableAction()
- disableAction(tabId)
- enableAction(tabId)
- getBadgeBgColor(tabId?)
- getBadgeText(tabId?)
- getBadgeTextColor(tabId?) [MV3]
- getActionPopup(tabId?)
- getActionTitle(tabId?)
- getActionUserSetting() [MV3]
- isActionEnabled(tabId)
- openActionPopup(windowId?) [MV3]
- setBadgeBgColor(color, tabId?)
- setBadgeText(text, tabId?)
- setBadgeTextColor(color, tabId?) [MV3]
- setActionIcon(details)
- setActionPopup(popup, tabId?)
- setActionTitle(title, tabId?)
- getDefaultPopup()
- clearBadgeText(tabId?)
isAvailableAction(method?: ApiMethodName<typeof chrome.action | typeof chrome.browserAction>): booleanThe optional method is a native function name, for example isAvailableAction("isEnabled").
Import the public ApiMethodName type from @addon-core/browser for your own typed helpers.
This checks callable presence without invoking the method; permissions and argument support still require handling.
Checks the same API selected by action methods and events: action for Manifest V3 and browserAction for Manifest V2. Does not fall back to the other namespace if the selected one is missing.
Returns false if the namespace or WebExtension environment is absent, or if accessing it throws.
The check is synchronous, does not log, and reads the current API on every call without caching.
Without an argument, it checks namespace presence only. Pass a native method name to also check that it is callable.
Neither form verifies permissions, argument support, or a successful operation. See method availability.
import {isAvailableAction} from "@addon-core/browser";
if (isAvailableAction()) {
// The namespace is present; handle operation-specific failures when using it.
}disableAction(tabId: number): Promise<void>
Disables the extension action for the specified tab. Falls back to chrome.browserAction.disable in MV2.
enableAction(tabId: number): Promise<void>
Enables the extension action for the specified tab. Falls back to chrome.browserAction.enable in MV2.
getBadgeBgColor(tabId?: number): Promise<[number, number, number, number]>
Retrieves the badge background color for a given tab.
getBadgeText(tabId?: number): Promise<string>
Retrieves the badge text for a given tab.
getBadgeTextColor(tabId?: number): Promise<[number, number, number, number]>
Retrieves the badge text color for a given tab (Manifest V3 only).
getActionPopup(tabId?: number): Promise<string>
Retrieves the popup URL set for the action in a given tab.
getActionTitle(tabId?: number): Promise<string>
Retrieves the title set for the action in a given tab.
getActionUserSetting(): Promise<chrome.action.UserSettings>
Retrieves the user settings for the action (Manifest V3 only).
isActionEnabled(tabId: number): Promise<boolean>
Checks whether the action is enabled for the specified tab.
openActionPopup(windowId?: number): Promise<void>
Programmatically opens the action popup (Manifest V3 only).
setBadgeBgColor(color: string | [number, number, number, number], tabId?: number): Promise<void>
Sets the badge background color for a given tab.
setBadgeText(text: string | number, tabId?: number): Promise<void>
Sets the badge text for a given tab.
setBadgeTextColor(color: string | [number, number, number, number], tabId?: number): Promise<void>
Sets the badge text color for a given tab (Manifest V3 only).
setActionIcon(details: chrome.action.TabIconDetails): Promise<void>
Sets the action icon for a tab or globally.
setActionPopup(popup: string, tabId?: number): Promise<void>
Sets the popup URL for the action in a given tab.
setActionTitle(title: string, tabId?: number): Promise<void>
Sets the title for the action in a given tab.
getDefaultPopup(): string | undefined
Reads the manifest once and returns its default popup setting: action.default_popup in MV3 or
browser_action.default_popup in MV2, using that snapshot's manifest_version.
| Manifest configuration | Result |
|---|---|
default_popup: "popup.html" |
The exact configured string, "popup.html" |
default_popup: "" |
The empty string, "" |
default_popup is absent |
undefined |
The selected action or browser_action section is absent |
undefined |
Errors reading the manifest propagate unchanged. The helper reads the manifest default; it does not query a
popup set dynamically or for a specific tab. Use getActionPopup(tabId) for the current action popup.
import {getDefaultPopup} from "@addon-core/browser";
const popup = getDefaultPopup();
if (popup !== undefined) {
// The configured string is available, including an explicit empty string.
console.log(popup);
} else {
console.log("No default popup is configured in the manifest.");
}Compatibility note: the return type changed from string to string | undefined. With strictNullChecks,
callers must narrow the result before assigning it to a required string or calling string methods.
Check against undefined when an explicit empty string must remain distinguishable from a missing setting.
An absent action section now returns undefined instead of causing a property-access error.
clearBadgeText(tabId?: number): Promise<void>
Clears the badge text for a given tab.
onActionClicked(callback: (tab: chrome.tabs.Tab) => void): () => void
Adds a listener for the action clicked event. Returns an unsubscribe function.
onActionUserSettingsChanged(callback: (settings: chrome.action.UserSettings) => void): () => void
Adds a listener for user settings changes on the action (Manifest V3 only). Returns an unsubscribe function.