Address bar button

Commonly referred to as a page action, this user interface option is a button added to the browser address bar. Users click the button to interact with your extension.

Use this button when a feature is only relevant for some web pages. By default, the address bar button is hidden in all browser tabs, and you call pageAction.show() and pageAction.hide() to show or hide it in specific tabs.

Compare to the toolbar button, which offers similar behavior but is used in situations where the extension's features are applicable to almost every web page.

Specifying the page action

You define the page action's properties using the page_action key in manifest.json:

"page_action": {
  "browser_style": true,
  "default_icon": {
    "19": "button/geo-19.png",
    "38": "button/geo-38.png"
  },
  "default_title": "Whereami?",
}

The only mandatory key is default_icon.

There are two ways to specify a page action: with or without a popup. If you don't specify a popup, when the user clicks the button an event is dispatched to the extension, which the extension listens for using pageAction.onClicked:

browser.pageAction.onClicked.addListener(handleClick);

If you specify a popup, the click event is not dispatched: instead, the popup is shown when the user clicks the button. The user is able to interact with the popup and it closes automatically when the user clicks outside it. See the Popup article for more details on creating and managing popups.

Note that your extension can have one page action only.

You can change any of the page action properties programmatically using the pageAction API.

Examples

The webextensions-examples repo on GitHub, contains several examples of extensions that use page action:

  • chill-out uses a page action without a popup.

Document Tags and Contributors

 Contributors to this page: andrewtruongmoz, hellosct1, rebloor, wbamberg
 Last updated by: andrewtruongmoz,