browser_action

Object
必須 いいえ
json

"browser_action": {
  "browser_style": true,
  "default_icon": {
    "16": "button/geo-16.png",
    "32": "button/geo-32.png"
  },
  "default_title": "Whereami?",
  "default_popup": "popup/geo.html",
  "theme_icons": [{
    "light": "icons/geo-16-light.png",
    "dark": "icons/geo-16.png",
    "size": 16
  }, {
    "light": "icons/geo-32-light.png",
    "dark": "icons/geo-32.png",
    "size": 32
  }]
}

browser action はあなたのブラウザーのツールバーに拡張機能のボタンを追加します。ボタンはアイコンと、オプションで HTML、CSS と JavaScript を使用した、ポップアップコンテンツを使用できます。

ポップアップを提供する場合は、ユーザーがボタンをクリックしたときポップアップが開かれ、ポップアップで実行されている JavaScript は、ユーザーの実行を処理できます。ポップアップを提供しない場合、ユーザーがボタンをクリックすると、クリックイベントが拡張機能のバックグラウンドスクリプトに送信されます。

You can also create and manipulate browser actions programmatically using the browserAction API.

構文

The browser_action key is an object that may have any of the following properties, all optional:

名前 説明
browser_style Boolean
New in Firefox 48

Optional, defaulting to false.

Use this to include a stylesheet in your popup that will make it look consistent with the browser's UI and with other extensions that use the browser_style property. Although this key defaults to false, it's recommended that you include it and set it to true.

In Firefox, the stylesheet can be seen at chrome://browser/content/extension.css, or chrome://browser/content/extension-mac.css on OS X.

The Firefox Style Guide describes the classes you can apply to elements in the popup in order to get particular styles.

The latest-download example extension uses browser_style in its popup.

default_area String
New in Firefox 54

Defines the part of the browser in which the button is initially placed. This is a string that may take one of four values:

  • "navbar": the button is placed in the main browser toolbar, alongside the URL bar.
  • "menupanel": the button is placed in a popup panel.
  • "tabstrip": the button is placed in the toolbar that contains browser tabs.
  • "personaltoolbar": the button is placed in the bookmarks toolbar.

This property is only supported in Firefox.

This property is optional, and defaults to "navbar".

An extension can't change the location of the button after it has been installed, but the user may be able to move the button using the browser's built-in UI customization mechanism.

default_icon Object or String

Use this to specify one or more icons for the browser action. The icon is shown in the browser toolbar 既定では.

Icons are specified as URLs relative to the manifest.json file itself.

You can specify a single icon file by supplying a string here:

json

"default_icon": "path/to/geo.svg"

To specify multiple icons in different sizes, specify an object here. The name of each property is the icon's height in pixels, and must be convertible to an integer. The value is the URL. 例えば、:

json

    "default_icon": {
      "16": "path/to/geo-16.png",
      "32": "path/to/geo-32.png"
    }

See Choosing icon sizes for more guidance on this.

default_popup 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.

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

これはローカライズ可能なプロパティです。

default_title String

Tooltip for the button, displayed when the user moves their mouse over it. If the button is added to the browser's menu panel, this is also shown under the app icon.

これはローカライズ可能なプロパティです。

theme_icons Array

This property enables you to specify different icons for dark and light themes.

If this property is present, it's an array containing at least one ThemeIcons object. A ThemeIcons object contains three properties, all mandatory:

"dark"
A URL pointing to an icon. This icon will be selected when themes with dark text are active (e.g. Firefox's Light theme, and the Default theme if no default_icon is specified).
"light"
A URL pointing to an icon. This icon will be selected when themes with light text are active (e.g. Firefox's Dark theme).
"size"
The size of the two icons in pixels.

Icons are specified as URLs relative to the manifest.json file itself.

You need to supply an ThemeIcons in size 16 and one in size 32 (for retina display).

アイコンサイズを選ぶ

The browser action's icon may need to be displayed in different sizes in different contexts:

  • The icon is displayed 既定では in the browser toolbar, but the user can move it into the browser's menu panel (the panel that opens when the user clicks the "hamburger" icon). The icon in the toolbar is smaller than the icon in the menu panel.
  • On a high-density display like a Retina screen, icons needs to be twice as big.

If the browser can't find an icon of the right size in a given situation, it will pick the best match and scale it. Scaling may make the icon appear blurry, so it's important to choose icon sizes carefully.

There are two main approaches to this. You can supply a single icon as an SVG file, and it will be scaled correctly:

json
"default_icon": "path/to/geo.svg"

Alternatively, you can supply several icons in different sizes, and the browser will pick the best match.

In Firefox:

So you can specify icons that match exactly, on both normal and Retina displays, by supplying three icon files, and specifying them like this:

json
    "default_icon": {
      "16": "path/to/geo-16.png",
      "32": "path/to/geo-32.png",
      "64": "path/to/geo-64.png"
    }

If Firefox can't find an exact match for the size it wants, then it will pick the smallest icon specified that's bigger than the ideal size. If all icons are smaller than the ideal size, it will pick the biggest icon specified.

json
"browser_action": {
  "default_icon": {
    "16": "button/geo-16.png",
    "32": "button/geo-32.png"
  }
}

A browser 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:

browser.browseAction.onClicked.addListener(handleClick);

json
"browser_action": {
  "default_icon": {
    "16": "button/geo-16.png",
    "32": "button/geo-32.png"
  },
  "default_title": "Whereami?",
  "default_popup": "popup/geo.html"
}

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

For a simple, but complete, extension that uses a browser action, see the walkthrough tutorial.

ブラウザーの互換性

BCD tables only load in the browser