browserAction

ブラウザーのツールバーにボタンを追加します。

ブラウザーアクションはブラウザーのツールバー内のボタンです。

これをボタンつきポップアップと関連付けられます。ポップアップは通常のウェブページ同様に、HTML, CSS, JavaScript を使って指定できます。ポップアップの中で動く JavaScript はバックグラウンドスクリプトとすべて同じ WebExtension API にアクセスできますが、グローバルコンテキストはブラウザーに表示される現在のページではなく、ポップアップになります。ウェブページに影響するには messages 経由で通信する必要があります。

ユーザーがアイコンをクリックした時に、ポップアップを指定していると、表示され — そしてコンテンツが読み込まれるでしょう 。ポップアップを指定していない時は、ユーザーがアイコンをクリックした時、拡張機能にイベントがディスパッチされます。

たいていのブラウザーアクションのプロパティは、manifest.json 内の browser_action キーを用いて宣言的に定義できます。

browserAction API では、次が可能です:

  • browserAction.onClicked を使ってアイコンのクリックをリッスンする
  • アイコンのプロパティ — アイコン、タイトル、ポップアップなど、の取得、設定。これはすべてのタブを通してグローバルにも、またはタブの ID を追加引数で渡すことで特定のタブだけにも取得、設定できます。

browserAction.ColorArray

RGBA 色を決める 0-255 の範囲の 4 整数の配列

browserAction.ImageDataType

画像のピクセルデータ。ImageData オブジェクト (例えば <canvas> 要素から) でないといけない。

関数

browserAction.setTitle()

ブラウザーアクションのタイトルをセットする。ツールチップに表示される。

browserAction.getTitle()

ブラウザーアクションのタイトルを取得します。

browserAction.setIcon()

ブラウザーアクションのアイコンをセットします。

browserAction.setPopup()

ユーザーがブラウザーアクションのアイコンをクリックした時に表示されるポップアップの HTML 文書をセットします。

browserAction.getPopup()

ブラウザーアクションのポップアップとしてセットされた HTML 文書を取得します。

browserAction.openPopup()

ブラウザーアクションのポップアップを開きます。

browserAction.setBadgeText()

ブラウザーアクションのバッジテキストをセットします。バッジはアイコンの上部に表示されます。

browserAction.getBadgeText()

ブラウザーアクションのバッジのテキストを取得します。

browserAction.setBadgeBackgroundColor()

バッジの背景色を指定します。

browserAction.getBadgeBackgroundColor()

バッジの背景色を取得します。

browserAction.enable()

タブのブラウザーアクションを有効にします。既定では、ブラウザーアクションはすべてのタブで有効です。

browserAction.disable()

タブのブラウザーアクションを無効にします。つまりタブがアクティブでもクリックできません。

browserAction.isEnabled()

ブラウザーアクションが有効か否かをチェックします。

イベント

browserAction.onClicked

ブラウザーアクションがクリックされた時に発火します。このイベントはブラウザーアクションがポップアップ付きでない場合は発火しません。

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
browserAction
ColorArray
ImageDataType
disable
enable
getBadgeBackgroundColor
details.windowId parameter
getBadgeText
details.windowId parameter
getBadgeTextColor
getPopup
details.windowId parameter
getTitle
details.windowId parameter
isEnabled
details.windowId parameter
onClicked
onClicked.OnClickData
onClicked.tab
openPopup
setBadgeBackgroundColor
details.windowId parameter
The color property of the details parameter can be set to null.
The color property of the details parameter can be set to a string.
setBadgeText
details.windowId parameter
The text property of the details parameter can be set to null.
setBadgeTextColor
setIcon
details.imageData parameter
details.windowId parameter
The path and imageData properties of the details parameter can be set to null.
setPopup
details.windowId parameter
The popup property of the details parameter can be set to null.
setTitle
details.windowId parameter
The title property of the details parameter can be set to null.

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.
User must explicitly enable this feature.
Has more compatibility info.

Example extensions

メモ: この API は Chromium の chrome.browserAction API に基づいています。この文書は Chromium コードの browser_action.json から得ています。Microsoft Edge の実装状況は Microsoft Corporation から提供されたものであり、ここでは Creative Commons Attribution 3.0 United States License に従っています。