An action is what happens when a user clicks the toolbar icon, usually called the [action icon](https://developer.chrome.com/docs/extensions/develop/ui.md.txt#action-icons) for your extension. An action [invokes an extension feature](https://developer.chrome.com/docs/extensions/reference/api/action.md.txt#event-onClicked) using the [Action API](https://developer.chrome.com/docs/extensions/reference/api/action.md.txt) or opens a [popup](https://developer.chrome.com/docs/extensions/develop/ui.md.txt#popups). This page shows how to invoke an extension feature. To use a popup, see [Add a popup](https://developer.chrome.com/docs/extensions/develop/ui/add-popup.md.txt).

## Register the action

To use the [`browser.action` API](https://developer.chrome.com/docs/extensions/reference/api/action.md.txt), add the `"action"` key to the extension's [manifest](https://developer.chrome.com/docs/extensions/reference/manifest.md.txt) file. See the [manifest section](https://developer.chrome.com/docs/extensions/reference/action#manifest) of the `browser.action` API reference for a full description of the optional properties of this field.

manifest.json:

```json
{
  "name": "My Awesome action Extension",
 ...
  "action": {
   ...
  }
 ...
}
```

## Respond to the action

Register an [`onClicked` handler](https://developer.chrome.com/docs/extensions/reference/action#event-onClicked) for when the user clicks the action icon. This event is not triggered if a popup is registered in the manifest.json file.

service-worker.js:

```json
browser.action.onClicked.addListener((tab) => {
  browser.action.setTitle({
    tabId: tab.id,
    title: `You are on tab: ${tab.id}`});
});
```

## Activate the action conditionally

The [`browser.declarativeContent` API](https://developer.chrome.com/docs/extensions/reference/api/declarativeContent.md.txt) lets you enable the extension's action icon based on the page URL or when CSS selectors match the elements on the page. When an extension's action icon is disabled, the icon is grayed out. If the user clicks the disabled icon, the extension's context menu appears.
![A disabled action icon](https://developer.chrome.com/static/docs/extensions/develop/ui/implement-action/images/disabled-extension.png) A disabled action icon.

## Action badge

Badges are bits of formatted text placed on top of the action icon to indicate such things as extension state or that actions are required by the user. To demonstrate this, the [Drink Water](https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/functional-samples/sample.water_alarm_notification) sample displays a badge with "ON" to show the user they have successfully set an alarm and displays nothing when the extension is idle. Badges can contain up to four characters.
![An extension icon without a badge and with a badge.](https://developer.chrome.com/static/docs/extensions/develop/ui/implement-action/images/badges.png) An extension icon with a badge (left) and without a badge (right).

Set the text of the badge by calling [`browser.action.setBadgeText()`](https://developer.chrome.com/docs/extensions/reference/api/action.md.txt#method-setBadgeText) and the background color by calling [`browser.action.setBadgeBackgroundColor()`](https://developer.chrome.com/docs/extensions/reference/api/action.md.txt#method-setBadgeBackgroundColor).

service-worker.js:

```json
browser.action.setBadgeText({text: 'ON'});
browser.action.setBadgeBackgroundColor({color: '#4688F1'});
```

## Tooltip

Register tooltips in the `"default_title"` field under the `"action"` key in the manifest.json file.

manifest.json:

```json
{
  "name": "Tab Flipper",
 ...
  "action": {
    "default_title": "Press Ctrl(Win)/Command(Mac)+Shift+Right/Left to flip tabs"
  }
...
}
```

You can also set or update tooltips by calling [`action.setTitle()`](https://developer.chrome.com/docs/extensions/reference/api/action.md.txt#method-setTitle). If no tooltip is set, the name of the extension displays.