page_action

Type Object
Mandatory No
Manifest version 2 or higher
Example
json
"page_action": {
  "default_icon": {
    "19": "button/geo-19.png",
    "38": "button/geo-38.png"
  },
  "default_title": "Whereami?",
  "default_popup": "popup/geo.html"
}

A page action is an icon that your extension adds inside the browser's URL bar.

Your extension may optionally also supply an associated popup whose content is specified using HTML, CSS, and JavaScript.

You must specify this key to include a page action in your extension. When specified, you can manipulate the button programmatically using the pageAction API.

If you supply a popup, then the popup is opened when the user clicks the icon, and your JavaScript running in the popup can handle the user's interaction with it. If you don't supply a popup, then a click event is dispatched to your extension's background scripts when the user clicks the icon.

Page actions are like browser actions, except that they are associated with particular web pages rather than with the browser as a whole. If an action is only relevant on certain pages, then you should use a page action and display it only on relevant pages. If an action is relevant to all pages or to the browser itself, use a browser action.

While browser actions are displayed by default, page actions are hidden by default. They can be shown for a particular tab by calling pageAction.show(), passing in the tab's id. You can also change this default behavior using the show_matches property.

Syntax

The page_action key is an object that may have any of three properties, all optional:

browser_style Optional

Boolean. Defaults to false.

Warning: Do not set browser_style to true: it's not supported in Manifest V3, starting from Firefox 118. See Manifest V3 migration for browser_style.

In Firefox, the stylesheet can be seen at chrome://browser/content/extension.css or chrome://browser/content/extension-mac.css on macOS. The latest-download example extension uses browser_style in its popup.

default_icon Optional

Object or String. Use this to specify an icon for the action.

It's recommended that you supply two icons here (19×19 pixels and 38×38 pixels), and specify them in an object with properties named "19" and "38", like this:

json
"default_icon": {
  "19": "geo-19.png",
  "38": "geo-38.png"
}

If you do this, then the browser will pick the right size icon for the screen's pixel density.

You can just supply a string here:

json
"default_icon": "geo.png"

If you do this, then the icon will be scaled to fit the toolbar, and may appear blurry.

You can use an SVG icon. You can also have the icon adapt to light and dark themes using a media query on prefers-color-scheme. For example:

css
#outside {
  fill: black;
}
#inside {
  fill: red;
}
@media (prefers-color-scheme: dark) {
  #outside {
    fill: white;
  }
  #inside {
    fill: black;
  }
}

For more information, see the themed-icons example.

Note: An implicit CSS filter applies to SVG icons in dark UI themes. This filter will be deactivated in Firefox Desktop version 152 (Firefox bug 2016509). You can test SVG icons with the CSS filter disabled by creating a boolean about:config preference called extensions.webextensions.pageActionIconDarkModeFilter.enabled and setting it to false. The filter is deactivated by default in Firefox Desktop Nightly from 149.

default_popup Optional

String. The path to an HTML file containing the specification of the popup. The HTML file may include CSS and JavaScript files using <link> and <script> elements, just like a normal web page.

However, don't use <script> with embedded code, because you'll get a Content Violation Policy error. Instead, <script> must use the src attribute to load a separate script file.

Unlike a normal web page, JavaScript running in the popup can access all the WebExtension APIs (subject to the extension having the appropriate permissions). This is a localizable property.

default_title Optional

String. Tooltip for the icon, displayed when the user moves their mouse over it. This is a localizable property.

hide_matches Optional

Array of MatchPattern except <all_urls>. Hide the page action by default for pages whose URLs match any of the given match patterns.

Note that page actions are always hidden by default unless show_matches is given. Therefore, it only makes sense to include this property if show_matches is also given, and will override the patterns in show_matches.

For example, consider a value like:

json
"page_action": {
  "show_matches": ["https://*.mozilla.org/*"],
  "hide_matches": ["https://developer.mozilla.org/*"]
}

This shows the page action by default for all HTTPS URLs under the "mozilla.org" domain, except for pages under "developer.mozilla.org".

show_matches Optional

Array of MatchPattern. Show the page action by default for pages whose URLs match any of the given patterns. See also hide_matches.

pinned Optional

Boolean. Optional. Defaults to true. Controls whether or not the page action should appear in the location bar by default when the user installs the extension. This property is no longer supported since Firefox 89.

Example

json
"page_action": {
  "default_icon": {
    "19": "button/geo-19.png",
    "38": "button/geo-38.png"
  }
}

A page action with just an icon, specified in 2 different sizes. The extension's background scripts can receive click events when the user clicks the icon using code like this:

js
browser.pageAction.onClicked.addListener(handleClick);
json
"page_action": {
  "default_icon": {
    "19": "button/geo-19.png",
    "38": "button/geo-38.png"
  },
  "default_title": "Whereami?",
  "default_popup": "popup/geo.html"
}

A page action with an icon, a title, and a popup. The popup will be shown when the user clicks the icon.

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
page_action
Chrome – Full support
Chrome 54 (Release date: 2016-10-12)
footnote
footnote Since Chrome 49, page actions are displayed on the toolbar, rather than in the address bar.
footnote If an extension defines a page action, it is not allowed to define a browser action as well.
footnote Available for use in Manifest V2 only.
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote
footnote Available for use in Manifest V2 only.
Firefox – Full support
Firefox 48 (Release date: 2016-08-02)
footnote Full support
Opera – Full support
Opera 41 (Release date: 2016-10-25)
footnote
footnote Since Opera 36, page actions are displayed on the toolbar, rather than in the address bar.
footnote If an extension defines a page action, it is not allowed to define a browser action as well.
footnote Available for use in Manifest V2 only.
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote
footnote If an extension defines a page action, it is not allowed to define a browser action as well.
footnote Available for use in Manifest V2 only.
Firefox for Android – Full support
Firefox for Android 57 (Release date: 2017-11-28)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote
footnote If an extension defines a page action, it is not allowed to define a browser action as well.
footnote Available for use in Manifest V2 only.
browser_style
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 48 (Release date: 2016-08-02)
footnote
footnote Removed from Manifest V3 in Firefox 118. See Browser styles for more details.
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
default_icon
Chrome – Full support
Chrome 72 (Release date: 2019-01-29)
footnote
footnote SVG icons are not supported.
Edge – Partial support
Edge 14 (Release date: 2016-08-02)
footnote Partial support
footnote SVG icons are not supported.
footnote 'default_icon' must be an object, with explicit sizes.
Firefox – Full support
Firefox 48 (Release date: 2016-08-02)
footnote Full support
Opera – Full support
Opera 60 (Release date: 2019-04-09)
footnote
footnote SVG icons are not supported.
Safari – Partial support
Safari 14 – 16.3 (Release date: 2020-09-16)
footnote Partial support
footnote SVG icons are not supported.
footnote Grayscale images are treated as template icons and processed with the system accent color and system appearance.
Safari – Full support
Safari 16.4 (Release date: 2023-03-27)
footnote
footnote Grayscale images are treated as template icons and processed with the system accent color and system appearance.
Firefox for Android – Full support
Firefox for Android 57 (Release date: 2017-11-28)
footnote Full support
Safari on iOS – Partial support
Safari on iOS 15.4 – 16.3 (Release date: 2022-03-14)
footnote Partial support
footnote SVG icons are not supported.
footnote Grayscale images are treated as template icons and processed with the system accent color and system appearance.
Safari on iOS – Full support
Safari on iOS 16.4 (Release date: 2023-03-27)
footnote
footnote Grayscale images are treated as template icons and processed with the system accent color and system appearance.
default_popup
Chrome – Full support
Chrome 72 (Release date: 2019-01-29)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 48 (Release date: 2016-08-02)
footnote Full support
Opera – Full support
Opera 60 (Release date: 2019-04-09)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 57 (Release date: 2017-11-28)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote Full support
default_title
Chrome – Full support
Chrome 72 (Release date: 2019-01-29)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 48 (Release date: 2016-08-02)
footnote Full support
Opera – Full support
Opera 60 (Release date: 2019-04-09)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 57 (Release date: 2017-11-28)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote Full support
hide_matches
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 59 (Release date: 2018-03-13)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – Full support
Firefox for Android 59 (Release date: 2018-03-13)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
pinned
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 64 (Release date: 2018-12-11)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
show_matches
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 59 (Release date: 2018-03-13)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
See implementation notes.
Has more compatibility info.

See also