Permissions-Policy: bluetooth 指令
HTTP Permissions-Policy 頭部的 bluetooth 指令控制當前文件是否允許使用 Web 藍牙 API。
具體來說,如果定義的策略不允許使用此功能,則由 Navigator.bluetooth 返回的 Bluetooth 物件的方法將阻止訪問。
Bluetooth.getAvailability()將始終使其返回的Promise以false的值兌現。Bluetooth.getDevices()將使其返回的Promise以SecurityErrorDOMException拒絕。Bluetooth.requestDevice()將使其返回的Promise以SecurityErrorDOMException拒絕。
語法
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 |
瀏覽器相容性
載入中…