Permissions-Policy: bluetooth 指令
HTTP Permissions-Policy
头部的 bluetooth
指令控制当前文档是否允许使用 Web 蓝牙 API。
具体来说,如果定义的策略不允许使用此功能,则由 Navigator.bluetooth
返回的 Bluetooth
对象的方法将阻止访问。
Bluetooth.getAvailability()
将始终使其返回的Promise
以false
的值兑现。Bluetooth.getDevices()
将使其返回的Promise
以SecurityError
DOMException
拒绝。Bluetooth.requestDevice()
将使其返回的Promise
以SecurityError
DOMException
拒绝。
语法
http
Permissions-Policy: bluetooth=<allowlist>;
<allowlist>
-
被授予使用此功能权限的源列表。有关更多详细信息,请参阅
Permissions-Policy
> 语法。
默认策略
bluetooth
的默认允许列表是 self
。
示例
一般示例
SecureCorp Inc. 希望在其自身源和源为 https://example.com
的所有浏览上下文中禁用 Web 蓝牙 API。它可以通过提供以下 HTTP 响应头来定义权限策略:
http
Permissions-Policy: bluetooth=(self "https://example.com")
使用 <iframe> 元素
FastCorp Inc. 希望为所有跨域子框架禁用 bluetooth
,除了一个特定的 <iframe>
。它可以通过提供以下 HTTP 响应头来定义权限策略:
http
Permissions-Policy: bluetooth=(self https://other.com/blue)
然后在 <iframe>
元素上包含一个 allow 属性
html
<iframe src="https://other.com/blue" allow="bluetooth"></iframe>
<iframe>
属性可以选择性地在某些框架中启用功能,而在其他框架中不启用,即使这些框架包含来自同一源的文档。
规范
规范 |
---|
Web 蓝牙 # permissions-policy |
浏览器兼容性
加载中…