この翻訳は不完全です。英語から この記事を翻訳 してください。

拡張機能のインストール後、実行時の特別なパーミッションを要求する。
 

拡張機能は強力な WebExtension API の多くにアクセスするパーミッションが必要です。manifest.json の permissions キーに必要なパーミッションを入れることで、インストール時にパーミッションを要求できます。インストール時にパーミッションを要求する主なメリットは次の通り:

  • the user is only asked once, so it's less disruptive for them and a simpler decision
  • the extension can rely on the access to the APIs it needs, because if it's running at all, the permissions have been granted.

There is not yet a simple GUI for users to view permissions of their installed WebExtension Add-ons.  Users must use about:debugging, then go to the Add-ons section, then use the "Manifest Url" link for the Add-on.  This will show raw json, which includes a "permissions" block that shows the permissions used by the addon.

With the permissions API, an extension can ask for additional permissions at runtime.These permissions need to be listed in the optional_permissions manifest.json key. Note that some permissions are not allowed in optional_permissions. The main advantages of this are:

  • the extension can run with a smaller set of permissions except when it actually needs them
  • the extension can handle permission denial in a graceful manner instead of presenting the user with a global "all or nothing" choice at install time. You can still get a lot out of that map extension without giving it access to your location, for example.
  • the extension may need host permissions, but not know at install time exactly which host permissions it needs. For example, the list of hosts may be a user setting. In this scenario, asking for a more specific range of hosts at runtime can be an alternative to asking for "<all_urls>" at install time.

To use the permissions API, decide which permissions your extension can request at runtime, and list them in optional_permissions. After this, you can request any permissions that were included in optional_permissions. Requests may only be made in the handler for a user action (for example, a click handler).
 

permissions.Permissions
Represents a set of permissions.

メソッド

permissions.contains()
Find out whether the extension has the given set of permissions.
permissions.getAll()
Get all the permissions this extension currently has.
permissions.remove()
Give up a set of permissions.
permissions.request()
Ask for a set of permissions.

Event handlers

permissions.onAdded
Fired when a new permission is granted.
permissions.onRemoved
Fired when a permission is removed.

ブラウザ実装状況

Update compatibility data on GitHub
デスクトップモバイル
ChromeEdgeFirefoxOperaAndroid 版 Firefox
containsChrome 完全対応 ありEdge 未対応 なしFirefox 完全対応 55Opera 完全対応 ありFirefox Android 完全対応 55
getAllChrome 完全対応 ありEdge 未対応 なしFirefox 完全対応 55Opera 完全対応 ありFirefox Android 完全対応 55
onAddedChrome 完全対応 ありEdge 未対応 なしFirefox 未対応 なしOpera 完全対応 ありFirefox Android 未対応 なし
onRemovedChrome 完全対応 ありEdge 未対応 なしFirefox 未対応 なしOpera 完全対応 ありFirefox Android 未対応 なし
PermissionsChrome 完全対応 ありEdge 未対応 なしFirefox 完全対応 55Opera 完全対応 ありFirefox Android 完全対応 55
removeChrome 完全対応 ありEdge 未対応 なしFirefox 完全対応 55Opera 完全対応 ありFirefox Android 完全対応 55
requestChrome 完全対応 ありEdge 未対応 なしFirefox 完全対応 55
補足
完全対応 55
補足
補足 The user will be prompted again for permissions that have been previously granted and then removed.
補足 It's not possible to request permissions from a popup or a sidebar document.
未対応 56 — 61
補足
補足 It's not possible to request permissions from an options page that's embedded in about:addons. To request permissions from an options page, set the open_in_tab property in the options_ui manifest key, so the options page opens in its own tab.
Opera 完全対応 ありFirefox Android 完全対応 55
補足
完全対応 55
補足
補足 The user will be prompted again for permissions that have been previously granted and then removed.
補足 It's not possible to request permissions from a popup or a sidebar document.
未対応 56 — 61
補足
補足 It's not possible to request permissions from an options page that's embedded in about:addons. To request permissions from an options page, set the open_in_tab property in the options_ui manifest key, so the options page opens in its own tab.

凡例

完全対応  
完全対応
未対応  
未対応
実装ノートを参照してください。
実装ノートを参照してください。

Example extensions

Acknowledgements

This API is based on Chromium's chrome.permissions API.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

ドキュメントのタグと貢献者

このページの貢献者: Uemmra3
最終更新者: Uemmra3,