# Web 蓝牙

**Web 蓝牙**（Web Bluetooth）是一个 JavaScript API，以 `navigator.bluetooth` 的形式暴露，允许网页发现用户选择的附近低功耗蓝牙设备，并通过 GATT（即[通用属性配置文件](https://www.edgepedia.org/zh/generic-attribute-profile)，[低功耗蓝牙](https://www.edgepedia.org/zh/bluetooth-low-energy)设备用它来暴露服务和特征）与这些设备通信。该规范由 W3C Web 蓝牙社区组以草案形式发布，并未进入 W3C 标准轨道<sup>[1](https://webbluetoothcg.github.io/web-bluetooth/)</sup>；该社区组将其目标描述为安全、保护隐私的网站与设备间通信，通过用户界面来选择和批准设备访问，而非依赖认证与安装<sup>[2](https://www.w3.org/groups/cg/web-bluetooth/)</sup>。该 API 的一个子集在 Android、ChromeOS、Mac 和 [Windows 10](https://www.edgepedia.org/zh/windows-10) 上的 Chrome 中无需标志即可使用<sup>[3](https://developer.chrome.com/docs/capabilities/bluetooth)</sup>，而 Firefox 和 Safari 已拒绝实现它<sup>[6](https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md)</sup>。

| 关键事实 | 详情 |
|---|---|
| 标准状态 | Web 蓝牙社区组草案；非 W3C 标准，亦不在标准轨道上<sup>[1](https://webbluetoothcg.github.io/web-bluetooth/)</sup> |
| 已发布版本 | Chrome Android 56（2017）、Chrome 56 Mac、Chrome 70 Windows（2018）、Edge 79（2020）；此后无新引擎实现<sup>[5](https://web-platform-dx.github.io/web-features-explorer/features/web-bluetooth/)</sup> |
| 未实现 | Firefox 和 Safari，二者均表明近期不支持<sup>[6](https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md)</sup> |
| 访问模型 | 仅限安全上下文；`requestDevice()` 需要瞬时激活并显示设备选择器；权限策略指令 `bluetooth` 默认为 `self`<sup>[7](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API)</sup> |
| 数据速率 | 蓝牙经典（BR/EDR）最高约 24 Mbps；蓝牙 4.0 低功耗限制在约 1 Mbps<sup>[1](https://webbluetoothcg.github.io/web-bluetooth/)</sup> |
| 写入大小 | 默认 ATT MTU 为 23 字节，留下 20 字节写入载荷；在协商 MTU 为 517 的情况下，在测试的 Windows 路径上无响应写入达到 514 字节载荷<sup>[8](https://www.januschka.com/chromium-webbluetooth-mtu.html)</sup> |
| 重连 | GATT 对象在断开连接时失效，必须重新获取；`getDevices()` 在页面重新加载后返回先前已授权的设备<sup>[3](https://developer.chrome.com/docs/capabilities/bluetooth)</sup><sup> • </sup><sup>[7](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API)</sup> |

## 背景：低功耗蓝牙与 GATT

该 API 面向低功耗蓝牙，而非蓝牙经典。规范对比了两种无线电模式：蓝牙“经典”（BR/EDR）支持最高约 24 Mbps 的速度，而蓝牙 4.0 的“低功耗”模式（BLE，或称“蓝牙智能”）限制在约 1 Mbps<sup>[1](https://webbluetoothcg.github.io/web-bluetooth/)</sup>。低功耗蓝牙设备通过 GATT 暴露其功能，GATT 是一个键值存储，组织为服务，每个服务包含特征，每个特征可携带描述符。网页读取特征值、写入特征值或订阅通知，以此控制打印机或 LED 显示屏，无需任何原生代码<sup>[10](https://googlechrome.github.io/samples/web-bluetooth/)</sup>。

ATT（属性协议）MTU 限制每次事务的大小。默认 MTU 为 23 字节时，写入命令的 3 个字节用于头部，因此仅剩 20 字节用于载荷。<sup>[8](https://www.januschka.com/chromium-webbluetooth-mtu.html)</sup> 设备可在连接建立期间协商更大的 MTU，从而允许每次事务更大的载荷，并可能提升批量写入吞吐量。

## API 工作原理

**发现。** 页面调用 `navigator.bluetooth.requestDevice(options)`，该调用必须由用户手势触发，如 `pointerup`、`click` 或 `touchend`<sup>[3](https://developer.chrome.com/docs/capabilities/bluetooth)</sup>。选项对象是必需的，可定义匹配广播 GATT 服务和/或设备名称的过滤器<sup>[3](https://developer.chrome.com/docs/capabilities/bluetooth)</sup>。该方法返回一个 Promise，以匹配选项的 `BluetoothDevice` 对象兑现；在没有选择器界面的情况下，它返回第一个匹配条件的设备<sup>[9](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice)</sup>。通常情况下，浏览器显示一个选择器，列出通过过滤器的附近设备，用户选择其一。

**连接与 GATT 操作。** 页面随后调用 `device.gatt.connect()`，并通过 `getPrimaryService()`、`getCharacteristic()` 和 `getDescriptor()` 遍历 GATT 树。它可以读取值、写入值（有响应或无响应），并订阅 `characteristicvaluechanged` 通知以获取流式数据。并行读写特征可能因平台不同而引发错误，因此 Chrome 的文档建议手动排队 GATT 操作请求<sup>[3](https://developer.chrome.com/docs/capabilities/bluetooth)</sup>。

**断开与重连。** Web [蓝牙](https://www.edgepedia.org/zh/bluetooth)将网站视为未与其访问的设备绑定：`BluetoothRemoteGATTService`、`BluetoothRemoteGATTCharacteristic` 和 `BluetoothRemoteGATTDescriptor` 对象在断开连接时失效<sup>[1](https://webbluetoothcg.github.io/web-bluetooth/)</sup>，代码在重连后必须始终重新获取这些属性<sup>[3](https://developer.chrome.com/docs/capabilities/bluetooth)</sup>。为了跨页面重新加载恢复，`Bluetooth.getDevices()` 检索先前授予该站点权限的设备<sup>[7](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API)</sup>，规范还描述了用于同一目的的 `query({name: 'bluetooth', ...})`<sup>[1](https://webbluetoothcg.github.io/web-bluetooth/)</sup>。Chrome 的官方示例演示了使用指数退避算法自动重连到断开的低功耗蓝牙设备<sup>[10](https://googlechrome.github.io/samples/web-bluetooth/)</sup>。

## 安全与隐私模型

该 API 仅在安全上下文中可用<sup>[3](https://developer.chrome.com/docs/capabilities/bluetooth)</sup><sup> • </sup><sup>[7](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API)</sup>。当 `requestDevice()` 请求尚未授权的设备时，会出现权限提示，调用全局对象必须具有瞬时激活——浏览器对真实用户手势刚刚发生的短暂记录<sup>[7](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API)</sup>。2019 年一项关于基于 Web 蓝牙的双因素认证的学术研究指出，草案禁止无用户交互的连接，旨在防止未经授权的网站在未经用户同意的情况下连接设备<sup>[11](https://floe.butterbrot.org/matrix/publications/dressel2019securicast.pdf)</sup>。

**能力披露与范围限定。** 由于 `requestDevice()` 授予对调用中指定的所有 GATT 服务的访问权限，用户代理必须在询问用户愿将哪些设备交由网站访问之前，告知用户这些服务赋予网站哪些能力，并且必须假定未知服务赋予对设备的完全控制<sup>[1](https://webbluetoothcg.github.io/web-bluetooth/)</sup>。访问权限由权限策略指令 `bluetooth` 限定，其默认允许列表为 `self`：同源框架可以使用该 API，但第三方内容默认被阻止，跨源使用需要在 Permissions-Policy 头部和 iframe `allow` 属性中同时指定源<sup>[7](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API)</sup>。用户代理还必须让用户检查哪些站点有权访问哪些设备，并撤销这些配对<sup>[1](https://webbluetoothcg.github.io/web-bluetooth/)</sup>，使用 `bluetooth` 权限调用 `navigator.permissions.query()` 会报告 `granted`、`denied` 或 `prompt` 状态<sup>[7](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API)</sup>。

**阻止已知易受攻击的攻击面。** 规范包含一个易受攻击的服务、特征和描述符的 GATT 阻止列表，以防止网站利用它们，并引用了 HID 设备——网站通信将允许[键盘记录](https://www.edgepedia.org/zh/keystroke-logging)<sup>[1](https://webbluetoothcg.github.io/web-bluetooth/)</sup>。该 API 从不向网站暴露蓝牙寻址、数据签名或加密密钥，这阻止了加密链路上的包中包注入攻击，尽管并非所有低功耗蓝牙设备都支持加密<sup>[1](https://webbluetoothcg.github.io/web-bluetooth/)</sup>。

**残余风险。** 社区组的用例文档警告说，与 WebGL 一样，许多蓝牙设备设计为仅由可信代码访问，将其暴露给 Web 可能导致从持续异常行为到完全沦陷的各种后果<sup>[12](https://webbluetoothcg.github.io/web-bluetooth/use-cases.html)</sup>。规范本身指出，被攻陷的源或跨站脚本可能让攻击者通过 Permission API 集成使用先前授权的设备<sup>[1](https://webbluetoothcg.github.io/web-bluetooth/)</sup>。2025 年 ACM Web 会议的一篇论文认为，基于 Chromium 的浏览器对 Web 蓝牙等设备 API 的支持从根本上改变了外设的威胁模型并增加了攻击面，因为设备不能再假定存在可信的操作系统主机<sup>[13](https://dl.acm.org/doi/10.1145/3696410.3714637)</sup>。

## 浏览器支持与标准状态

Chromium 系浏览器承载了该实现。GATT 通信 API 在 Android、ChromeOS、Mac 和 Windows 上的 Chrome 中无需任何标志即可使用；Linux 仅部分实现，需要 `enable-experimental-web-platform-features` 标志<sup>[6](https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md)</sup>。Windows 实现随 Chrome 70.0.3526.0 推出，需要 Windows 10 版本 1703（创意者更新）<sup>[6](https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md)</sup>。[Microsoft Edge](https://www.edgepedia.org/zh/microsoft-edge) 自版本 79 起支持 Web 蓝牙<sup>[6](https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md)</sup>，三星 Internet 自版本 6.4 起无需标志即支持<sup>[14](https://samsunginternet.github.io/docs/web-bluetooth)</sup>。

Firefox 和 Safari 均已拒绝。实现状态记录将 Firefox 列为不支持，且根据 Mozilla 标准立场近期无支持计划<sup>[6](https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md)</sup>，Safari 同样如此，理由是反指纹识别担忧和 [WebKit](https://www.edgepedia.org/zh/webkit) 缺陷 101034<sup>[6](https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md)</sup>。在 iOS 和 iPadOS 上，Safari 没有原生支持，一个名为 iOSWebBLE 的第三方 Safari Web 扩展通过桥接到 CoreBluetooth 来补充实现 `navigator.bluetooth`，提供的是用户态而非 WebKit 支持<sup>[4](https://caniuse.com/web-bluetooth)</sup>。

该规范仍为社区组草案。它明确声明自己既非 W3C 标准，也不在 W3C 标准轨道上<sup>[1](https://webbluetoothcg.github.io/web-bluetooth/)</sup>。

## 数据一览

- 无线电速率：BR/EDR 最高约 24 Mbps；蓝牙 4.0 低功耗约 1 Mbps<sup>[1](https://webbluetoothcg.github.io/web-bluetooth/)</sup>。
- ATT MTU：默认 23 字节，写入命令头部 3 字节，载荷 20 字节；在测试的 Windows 路径上，有效 MTU 为 517 时，无响应写入达到 514 字节载荷<sup>[8](https://www.januschka.com/chromium-webbluetooth-mtu.html)</sup>。
- 实际流传输：一位开发者的 500 样本/秒 × 8 通道 × 24 字节（96 kB/s）流超出了浏览器缓冲限制，而 250 样本/秒运行基本无问题；另一位报告了 Android Web BLE 上 20-MTU 数据包大小限制，并转向原生库进行移动流传输<sup>[15](https://github.com/WebBluetoothCG/web-bluetooth/issues/569)</sup>。
- 功能里程碑：制造商数据过滤器于 Chrome 92，排除过滤器于 Chrome 114，无响应写入于 Chrome 85，通知变体于 Chrome 70<sup>[6](https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md)</sup>。

这些数字界定了用例范围。默认 20 字节写入载荷适合命令和小型传感器读取；任何类似音频、批量固件传输或高速遥测的需求都需要协商 MTU、仔细排队或原生 API。

## 与 Web Serial 及原生 BLE 的比较

Web 蓝牙仅覆盖 BLE/GATT。对于暴露 RFCOMM 服务的蓝牙经典设备，Chrome 的文档引导开发者改用 Web Serial API<sup>[3](https://developer.chrome.com/docs/capabilities/bluetooth)</sup>，使 Web Serial 成为与暴露 RFCOMM 的蓝牙经典设备通信的另一种方案。与 CoreBluetooth 或 Android BLE API 等原生栈相比，Web API 以能力换取覆盖面：它不能暴露密钥或原始寻址，写入大小遵循协商的 MTU，而在 Android 上，遇到 20-MTU Web 限制的开发者已转向原生库进行流传输<sup>[15](https://github.com/WebBluetoothCG/web-bluetooth/issues/569)</sup>。在 iOS 上，有文档记载的路径是 iOSWebBLE 扩展桥接到 CoreBluetooth，而非原生浏览器实现<sup>[4](https://caniuse.com/web-bluetooth)</sup>。

## 近期发展

实现格局一直稳定。web-features 查询工具将最后一个新引擎实现记为 2020-01-15 的 Edge 79，此前有 Chrome Android 56（2017-02-01）和 Chrome 70（2018-10-16），Firefox 和 Safari 仍不支持<sup>[5](https://web-platform-dx.github.io/web-features-explorer/features/web-bluetooth/)</sup>。在 Chromium 内部，`getDevices()`（自 Chrome 83）和 `watchAdvertisements()`（自 Chrome 85）仍需启用 `enable-experimental-web-platform-features` 标志才能使用，持久设备权限仍需启用 `enable-web-bluetooth-new-permissions-backend` 标志才能使用<sup>[6](https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md)</sup>。跟踪记录中最近发布的功能是 Chrome 114 的排除过滤器<sup>[6](https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md)</sup>。Firefox 和 Safari 的否定立场持续<sup>[5](https://web-platform-dx.github.io/web-features-explorer/features/web-bluetooth/)</sup>。

## 应用与实践

Chrome 的官方示例库展示了该 API 驱动 LED 显示屏和打印机，并包含指数退避自动重连模式<sup>[10](https://googlechrome.github.io/samples/web-bluetooth/)</sup>。社区组的演示和研究文献增加了传感器流传输和认证：SecuriCast 项目使用 Web 蓝牙实现零接触双因素认证，并指出用户交互要求是该设计的局限<sup>[11](https://floe.butterbrot.org/matrix/publications/dressel2019securicast.pdf)</sup>。

供应商文档中的实用指南源于 API 的结构：排队 GATT 操作而非并行发出读写<sup>[3](https://developer.chrome.com/docs/capabilities/bluetooth)</sup>，每次重连后重新获取所有 GATT 对象<sup>[3](https://developer.chrome.com/docs/capabilities/bluetooth)</sup>，并使用 `getDevices()` 加上重连例程以在重新加载和链路断开后恢复<sup>[7](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API)</sup><sup> • </sup><sup>[10](https://googlechrome.github.io/samples/web-bluetooth/)</sup>。吞吐量敏感的设计应围绕上述 MTU 计算进行规划，并在每个目标平台上测试，因为缓冲限制和 MTU 行为各不相同<sup>[15](https://github.com/WebBluetoothCG/web-bluetooth/issues/569)</sup><sup> • </sup><sup>[8](https://www.januschka.com/chromium-webbluetooth-mtu.html)</sup>。

## References

1. [Web Bluetooth Specification, Web Bluetooth Community Group draft](https://webbluetoothcg.github.io/web-bluetooth/)
2. [Web Bluetooth Community Group, W3C](https://www.w3.org/groups/cg/web-bluetooth/)
3. [Communicating with Bluetooth devices over JavaScript, Chrome for Developers](https://developer.chrome.com/docs/capabilities/bluetooth)
4. [Web Bluetooth, Can I use](https://caniuse.com/web-bluetooth)
5. [Web features explorer: Web Bluetooth](https://web-platform-dx.github.io/web-features-explorer/features/web-bluetooth/)
6. [Implementation status, WebBluetoothCG](https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md)
7. [Web Bluetooth API, MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API)
8. [Web Bluetooth: How Large Can a Write Be?, januschka.com](https://www.januschka.com/chromium-webbluetooth-mtu.html)
9. [Bluetooth: requestDevice() method, MDN](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice)
10. [Web Bluetooth Samples, Google Chrome](https://googlechrome.github.io/samples/web-bluetooth/)
11. [SecuriCast: Zero-Touch Two-Factor Authentication using WebBluetooth (2019)](https://floe.butterbrot.org/matrix/publications/dressel2019securicast.pdf)
12. [Web Bluetooth Use Cases, WebBluetoothCG](https://webbluetoothcg.github.io/web-bluetooth/use-cases.html)
13. [Peripheral Instinct: How External Devices Breach Browser Sandboxes, ACM Web Conference 2025](https://dl.acm.org/doi/10.1145/3696410.3714637)
14. [Web Bluetooth, Samsung Internet developer docs](https://samsunginternet.github.io/docs/web-bluetooth)
15. [Streaming BLE5 PHY data rates, WebBluetoothCG issue #569](https://github.com/WebBluetoothCG/web-bluetooth/issues/569)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Web development and web-platform technologies › Device and hardware Web APIs

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/web-bluetooth

English original: https://www.edgepedia.org/web-bluetooth
