In the following figure, the multicolored square to the right of the address bar is the icon for a browser action. A popup is below the icon.

If you want to create an icon that isn't always visible, use a page action instead of a browser action.

Manifest

Register your browser action in the extension manifest like this:

{
  "name": "My extension",
  ...
  "browser_action": {
    "default_icon": {                    // optional
      "19": "images/icon19.png",           // optional
      "38": "images/icon38.png"            // optional
    },
    "default_title": "Google Mail",      // optional; shown in tooltip
    "default_popup": "popup.html"        // optional
  },
  ...
}

If you only provide one of the 19px or 38px icon size, the extension system will scale the icon you provide to the pixel density of the user's display, which can lose detail or make it look fuzzy. The old syntax for registering the default icon is still supported:

{
  "name": "My extension",
  ...
  "browser_action": {
    ...
    "default_icon": "images/icon19.png"  // optional
    // equivalent to "default_icon": { "19": "images/icon19.png" }
  },
  ...
}

Parts of the UI

A browser action can have an icon, a tooltip, a badge, and a popup.

Icon

Browser action icons can be up to 19 dips (device-independent pixels) wide and high. Larger icons are resized to fit, but for best results, use a 19-dip square icon.

You can set the icon in two ways: using a static image or using the HTML5 canvas element. Using static images is easier for simple applications, but you can create more dynamic UIs — such as smooth animation — using the canvas element.

Static images can be in any format WebKit can display, including BMP, GIF, ICO, JPEG, or PNG. For unpacked extensions, images must be in the PNG format.

To set the icon, use the default_icon field of browser_action in the manifest, or call the $ref:browserAction.setIcon method.

To properly display icon when screen pixel density (ratio size_in_pixel / size_in_dip) is different than 1, the icon can be defined as set of images with different sizes. The actual image to display will be selected from the set to best fit the pixel size of 19 dip icon. At the moment, the icon set can contain images with pixel sizes 19 and 38.

Tooltip

To set the tooltip, use the default_title field of browser_action in the manifest, or call the $ref:browserAction.setTitle method. You can specify locale-specific strings for the default_title field; see Internationalization for details.

Badge

Browser actions can optionally display a badge — a bit of text that is layered over the icon. Badges make it easy to update the browser action to display a small amount of information about the state of the extension.

Because the badge has limited space, it should have 4 characters or less.

Set the text and color of the badge using $ref:browserAction.setBadgeText and $ref:browserAction.setBadgeBackgroundColor, respectively.

Popup

If a browser action has a popup, the popup appears when the user clicks the icon. The popup can contain any HTML contents that you like, and it's automatically sized to fit its contents.

To add a popup to your browser action, create an HTML file with the popup's contents. Specify the HTML file in the default_popup field of browser_action in the manifest, or call the $ref:browserAction.setPopup method.

Tips

For the best visual impact, follow these guidelines:

Examples

You can find simple examples of using browser actions in the examples/api/browserAction directory. For other examples and for help in viewing the source code, see Samples.