这篇翻译不完整。请帮忙从英语翻译这篇文章

值类型 数组
强制性 不强制
示例
"permissions": [
  "*://developer.mozilla.org/*",
  "webRequest"
]

使用permissions 关键字为你的扩展请求特殊的权限。该关键字为一个字符串数列,每个字符串请求一项权限。

如果你使用该关键字请求权限,浏览器可能会在安装该扩展时通知用户该扩展需求某些权限,并询问他们是否愿意给予这些权限。浏览器也可能允许用户检查扩展的权限。

该关键字能够包含三种类型的权限:

  • 主机权限
  • API 权限
  • 活动标签权限

主机权限

 主机权限使用 match patterns 指定,扩展在每一个表达式指定的网址上请求额外权限。

额外权限包括:

  • XMLHttpRequestfetch 用于访问无跨源限制的源文件(包括从content scripts发出的访问请求)
  • 以编程方式(使用 tabs.executeScript)将脚本注入到来自源服务器(origins)提供的页面的功能。
  • 使用 webRequest 在其主机上获取消息的能力。
  • 使用 cookies API 访问主机cookies的能力,只要 cookies api的权限也被请求。
  • 使用无通配符(*)的全域名会绕开跟踪保护机制,但不能与 <all_urls> 共用.

Firefox浏览器,自56以后的版本,扩展都会自动获取其源的主机权限,如以下形式:

moz-extension://60a20a9b-1ad4-af49-9b6c-c64c98c37920/

60a20a9b-1ad4-af49-9b6c-c64c98c37920 是扩展内部ID。编程时可使用 extension.getURL() 来返回此URL路径:

  1. browser.extension.getURL("");
    // moz-extension://60a20a9b-1ad4-af49-9b6c-c64c98c37920/

API 权限

API 权限有关键字指定,每个关键字标志着一类WebExtension API 能够被使用。

如下关键字是当前可用的:

  • activeTab
  • alarms
  • bookmarks
  • browsingData
  • browserSettings
  • contextMenus
  • contextualIdentities
  • cookies
  • downloads
  • downloads.open
  • find
  • geolocation
  • history
  • identity
  • idle
  • management
  • menus
  • nativeMessaging
  • notifications
  • pkcs11
  • privacy
  • proxy
  • sessions
  • storage
  • tabs
  • theme
  • topSites
  • webNavigation
  • webRequest
  • webRequestBlocking

在大部分情况下这种权限仅仅允许你访问API,除了以下情况:

  • tabs让你可以访问 一部分特权API: Tab.url, Tab.title, and Tab.faviconUrl。在Firefox中你也需要tabs 来将queryInfo中的url参数加入 tabs.query(). 剩余的tabs API能在不要求任何权限的情况被使用
  • webRequestBlocking 允许你是用“blocking”参数,所以你可以 修改或取消requests.
  • downloads.open 让你使用 downloads.open() API.

活动标签权限

该权限被指定为“activeTab”。如果一个扩展拥有activeTab权限,当用户跟该扩展交互时,扩展仅在活动标签被赋予额外权限。

“用户交互”包括:

  • 用户点击扩展的浏览器按钮或者页面按钮
  • 用户选择了扩展的上下文菜单
  • 用户敲击了扩展定义的快捷键

额外特权包括:

改权限的目的是为了在不给予扩展太多权限的情况下,使得扩展能够应付大部分情况。很多扩展需要在用户要求时,在当前页面做一些处理,比如,考虑一个扩展想要在用户点击一个浏览器按钮时在当前页面运行一个脚本,如果 activeTab 权限不存在,扩展将需要请求主机权限<all_urls>,但是这给予了扩展超过其需要的权限:现在它可以在任何任何时间标签页执行脚本任何次,而不是仅仅在活动标签而且仅仅回应用户的行为。

剪贴板访问

有两种权限使得WebExtentsion可以跟剪贴板交互:

  • clipboardWrite: 使用document.execCommand("copy") 或document.execCommand("cut") 向剪贴板写入
  • clipboardRead: 使用 document.execCommand("paste") 从剪贴板读取

查看 Interact with the clipboard 获取更多

无限制存储

unlimitedStorage 权限:

示例

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

请求 developer.mozilla.org 下的权限访问.

  "permissions": ["tabs"]

请求tabs API的权限需要部分的访问。

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

请求以上两种访问。

浏览器兼容性

本页的兼容列表是从结构化数据生成的。如果你想参与修改此数据,请参考 https://github.com/mdn/browser-compat-data 并发送pull 请求。

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
Basic supportChrome Full support YesEdge Full support 14Firefox Full support 48Opera Full support YesFirefox Android Full support 48
activeTabChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android Full support 48
alarmsChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48
backgroundChrome Full support 10Edge No support NoFirefox No support NoOpera No support NoFirefox Android No support No
bookmarksChrome Full support YesEdge Full support 15Firefox Full support 45Opera Full support YesFirefox Android No support No
browserSettingsChrome No support NoEdge No support NoFirefox Full support 56Opera No support NoFirefox Android Full support 56
browsingDataChrome Full support YesEdge No support NoFirefox Full support 53Opera Full support YesFirefox Android Full support 56
clipboardReadChrome Full support YesEdge No support NoFirefox Full support 54Opera Full support YesFirefox Android Full support 54
clipboardWriteChrome Full support YesEdge No support NoFirefox Full support 51Opera Full support YesFirefox Android Full support 51
contentSettingsChrome Full support YesEdge No support NoFirefox No support NoOpera Full support YesFirefox Android No support No
contextMenusChrome Full support YesEdge Full support 14Firefox Full support 55
Notes
Full support 55
Notes
Notes Available as an alias to the menus permission.
Opera Full support YesFirefox Android No support No
contextualIdentitiesChrome No support NoEdge No support NoFirefox Full support 53Opera No support NoFirefox Android Full support 53
cookiesChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 48
debuggerChrome Full support YesEdge No support NoFirefox No support NoOpera Full support YesFirefox Android No support No
dnsChrome No support NoEdge No support NoFirefox Full support 60Opera No support NoFirefox Android Full support 60
downloadsChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 48
downloads.openChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android Full support 48
findChrome No support NoEdge No support NoFirefox Full support 57Opera No support NoFirefox Android No support No
geolocationChrome Full support YesEdge Full support 14Firefox Full support 54Opera Full support YesFirefox Android Full support 54
historyChrome Full support YesEdge No support NoFirefox Full support 49Opera Full support YesFirefox Android No support No
identityChrome Full support YesEdge No support NoFirefox Full support 53Opera Full support YesFirefox Android No support No
idleChrome Full support YesEdge Full support 15Firefox Full support 45Opera Full support YesFirefox Android Full support 48
managementChrome Full support YesEdge No support NoFirefox Full support 51Opera Full support YesFirefox Android Full support 51
menusChrome No support NoEdge No support NoFirefox Full support 53Opera No support NoFirefox Android No support No
nativeMessagingChrome Full support 29Edge Full support 15Firefox Full support 50Opera Full support 16Firefox Android No support No
notificationsChrome Full support 5Edge No support NoFirefox Full support 45Opera Full support 25Firefox Android Full support 48
pageCaptureChrome Full support YesEdge No support NoFirefox No support NoOpera Full support YesFirefox Android No support No
pkcs11Chrome No support NoEdge No support NoFirefox Full support 58Opera No support NoFirefox Android No support No
privacyChrome Full support YesEdge No support NoFirefox Full support 54Opera Full support YesFirefox Android Full support 54
proxyChrome No support NoEdge No support NoFirefox Full support 55Opera No support NoFirefox Android Full support 55
sessionsChrome Full support YesEdge No support NoFirefox Full support 52Opera Full support YesFirefox Android No support No
storageChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 48
tabsChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 54
themeChrome No support NoEdge No support NoFirefox Full support 55Opera No support NoFirefox Android No support No
topSitesChrome Full support YesEdge No support NoFirefox Full support 52Opera Full support YesFirefox Android Full support 52
unlimitedStorageChrome Full support YesEdge Full support 14Firefox Full support 56Opera No support NoFirefox Android Full support 56
webNavigationChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support 17Firefox Android Full support 48
webRequestChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 48
webRequestBlockingChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 48

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

文档标签和贡献者

标签: 
最后编辑者: zhengkai2001,