connect.action
The toolbar button β badge, icon, title, enable/disable, and onClicked.
The toolbar button is your own surface, so the whole namespace needs no capability. Use it to show a badge, swap the icon, set the tooltip, enable/disable the button, and react to clicks.
- Capability: none (your own surface)
- Namespace:
connect.action
Declare the button (and optionally its popup) in the manifest:
"ui": { "action": { "entry": "popup.html", "defaultTitle": "My Extension" } }Omit entry for a popup-less button that fires action.onClicked
instead.
public/docs-img/extensions/action-badge.pngWalkthrough
Show an unread count on the button.
- Declare the action in
ui.action(no capability needed). - Set the badge from your background as state changes:
await connect.action.setBadgeText(String(unread || '')); await connect.action.setBadgeBackgroundColor('#16a34a'); - Clear it by setting
''. - For a popup-less button, handle
onClickedinstead of declaringentry.
Methods
action.setBadgeText(text)
How to use it
- Pass a short string to show, or
''to hide the badge.
Signature β connect.action.setBadgeText(text | { text })
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
text | string | yes | The badge label. '' hides the badge. |
Returns β Promise<void>.
action.setBadgeBackgroundColor(color)
How to use it
- Pass a CSS color for the badge background.
Signature β connect.action.setBadgeBackgroundColor(color | { color }) Β· Returns
Promise<void>.
action.getBadgeText() Β· action.getBadgeBackgroundColor()
Read the current badge text / color.
How to use it
- Call to read the current value (e.g. to toggle or increment).
Returns β Promise<string>.
action.setIcon(path)
Swap the button icon.
How to use it
- Pass an extension-relative asset path, or
''to revert to the manifest icon.
Signature β connect.action.setIcon(path | { path })
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | yes | An extension-relative asset. '' reverts to the manifest icon. |
Returns β Promise<void>.
action.setTitle(title) Β· action.getTitle()
Tooltip override; '' reverts to the manifest defaultTitle.
How to use it
setTitle(text)to override the tooltip;''to revert.getTitle()reads it.
Signature β connect.action.setTitle(title | { title }) / action.getTitle()
Returns β Promise<void> / Promise<string>.
action.enable() Β· action.disable() Β· action.isEnabled()
Grey / ungrey the button.
How to use it
disable()to grey it out (clicks ignored);enable()to restore;isEnabled()to read state.
Returns β Promise<void> / Promise<void> / Promise<boolean>.
action.openPopup()
Programmatically open the popup β or fire onClicked for a popup-less action.
How to use it
- Call it to open the popup from code (e.g. after a background event).
Returns β Promise<void>.
Events
action.onClicked(cb)
Fires when the button is clicked β only when the action declares no popup
(ui.action without entry); a declared popup opens instead.
How to use it
- Omit
entryinui.actionso the button has no popup. - Subscribe to
onClickedand do your thing (open a tab, toggle state).
Payload β none. Sticky, and wakes a suspended background.
connect.action.onClicked(() => connect.tabs.create('https://example.com'));Notes
- The badge/title/icon setters are live β call them from the background or popup as state changes.
- For a popup that resizes with its content, see
connect.uiβsetPopupSize.
