optional_permissions 编辑

TypeArray
MandatoryNo
Example
"optional_permissions": [
  "*://developer.mozilla.org/*",
  "webRequest"
]

Use the optional_permissions key to list permissions that you want to ask for at runtime, after your extension has been installed.

The permissions key lists permissions that your extension needs before it can be installed. In contrast, optional_permissions lists permissions that your extension doesn't need at install time but it may ask for after it has been installed. To ask for a permission, use the permissions API. Asking for a permission may present the user with a dialog requesting them to grant the permission to your extension.

For advice on designing your request for runtime permissions, to maximize the likelihood that users grant them, see Request permissions at runtime.

Starting with Firefox 84, users will be able to manage optional permissions from the Firefox Add-ons Manager. Extensions that use optional permissions should listen for browser.permissions.onAdded and browser.permissions.onRemoved API events to know when a user grants or revokes these permissions.

The key can contain two kinds of permissions: host permissions and API permissions.

Host permissions

These are the same as the host permissions you can specify in the permissions key.

API permissions

You can include any of the following here, but not in all browsers: check the compatibility table for browser-specific details.

  • activeTab
  • background
  • bookmarks
  • browserSettings
  • clipboardRead
  • clipboardWrite
  • contentSettings
  • contextMenus
  • cookies
  • debugger
  • downloads
  • downloads.open
  • find
  • geolocation
  • history
  • idle
  • management
  • notifications
  • pageCapture
  • privacy
  • tabHide
  • tabs
  • topSites
  • webNavigation
  • webRequest
  • webRequestBlocking

Note that this is a subset of the API permissions allowed in permissions.

Of this set, the following permissions are granted silently, without a user prompt: activeTab, cookies, idle, webRequest, webRequestBlocking.

Example

 "optional_permissions": ["*://developer.mozilla.org/*"]

Enable the extension to ask for privileged access to pages under developer.mozilla.org.

  "optional_permissions": ["tabs"]

Enable the extension to ask for access to the privileged pieces of the tabs API.

  "optional_permissions": ["*://developer.mozilla.org/*", "tabs"]

Enable the extension to ask for both of the above permissions.

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:55 次

字数:5156

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文