BrowserActionPort
BrowserActionPort is the Manifest V2 toolbar button API; it is superseded by ActionPort for all new development.
Deprecated
This port targets the legacy browser_action MV2 API. Use ActionPort for all new implementations.
Context
- Availability: Background
- Source:
packages/ports/src/background/browser-action/browser-action.port.ts
Key Methods
setTitle(details: { title: string; tabId?: number }): Promise<void>- Set button tooltip text.setBadgeText(details: { text: string; tabId?: number }): Promise<void>- Set badge label.setBadgeBackgroundColor(details: { color: string; tabId?: number }): Promise<void>- Set badge color.setIcon(details: { path?: string | { [size: number]: string }; tabId?: number; imageData?: any }): Promise<void>- Set button icon.
Usage
import { BrowserActionPort } from '@hexajs-dev/ports';
import { Injectable, HexaContext } from '@hexajs-dev/common';
@Injectable({ context: HexaContext.Background })
export class LegacyStatusService {
constructor(private readonly browserAction: BrowserActionPort) {}
async setActiveState(tabId: number) {
await this.browserAction.setBadgeText({ text: 'ON', tabId });
await this.browserAction.setBadgeBackgroundColor({ color: '#107C10', tabId });
}
}
API Reference Appendix
Below is the exhaustive, auto-generated technical reference for all types, interfaces, and signatures associated with this API.
Classes
BrowserActionPort
import { BrowserActionPort } from '@hexajs-dev/ports';
class BrowserActionPort { ... }
Methods
onClickedAddListener()
onClickedAddListener(listener: (tab: HexaWebTab) => void): void
onClickedRemoveListener()
onClickedRemoveListener(listener: (tab: HexaWebTab) => void): void
setBadgeBackgroundColor()
setBadgeBackgroundColor(details: SetBadgeBackgroundColorDetails): Promise<void>
setBadgeText()
setBadgeText(details: SetBadgeTextDetails): Promise<void>
setIcon()
setIcon(details: SetIconDetails): Promise<void>
setTitle()
setTitle(details: SetTitleDetails): Promise<void>
Supporting Types
SetBadgeBackgroundColorDetails
interface SetBadgeBackgroundColorDetails {
color: string;
tabId?: number;
}
SetBadgeTextDetails
interface SetBadgeTextDetails {
text: string;
tabId?: number;
}
SetIconDetails
interface SetIconDetails {
path?: string | {
[size: number]: string;
};
tabId?: number;
imageData?: any;
}
SetTitleDetails
interface SetTitleDetails {
title: string;
tabId?: number;
}