Permissions-Policy: bluetooth
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
HTTP Permissions-Policy 标头的 bluetooth 指令控制当前文档是否被允许使用 Web Bluetooth API。
具体来说,如果定义的策略不允许使用此特性,则由 Navigator.bluetooth 返回的 Bluetooth 对象的方法将会阻止访问:
Bluetooth.getAvailability()将始终以false的值兑现其返回的Promise。Bluetooth.getDevices()将以SecurityError类型的DOMException拒绝其返回的Promise。Bluetooth.requestDevice()将以SecurityError类型的DOMException拒绝其返回的Promise。
语法
http
Permissions-Policy: bluetooth=<allowlist>;
<allowlist>-
允许使用该特性的来源列表。请参阅
Permissions-Policy> 语法了解更多详细信息。
默认策略
bluetooth 的默认允许列表为:self。
示例
>通用示例
SecureCorp Inc. 希望在所有浏览上下文中禁用 Web Bluetooth API,除了其自身的来源和来源 https://example.com。它可以通过发送以下 HTTP 响应标头来定义权限策略:
http
Permissions-Policy: bluetooth=(self "https://example.com")
带有 <iframe> 元素
FastCorp Inc. 希望为除了特定的 <iframe> 的所有跨来源的子框架禁用 bluetooth。它可以通过发送以下 HTTP 响应标头来定义权限策略:
http
Permissions-Policy: bluetooth=(self https://other.com/blue)
然后在 <iframe> 元素上包含一个 allow 属性:
html
<iframe src="https://other.com/blue" allow="bluetooth"></iframe>
<iframe> 属性可以有选择地在某些框架中启用特性,而在其他框架中禁用这些特性,即使这些框架包含来自同一来源的文档。
规范
| Specification |
|---|
| Web Bluetooth> # permissions-policy> |
浏览器兼容性
Loading…