此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Bluetooth:getDevices() 方法

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

安全上下文: 此特性仅在一些支持的浏览器安全上下文(HTTPS)中可用。

Bluetooth 接口的 getDevices() 方法返回包含此来源被允许访问的蓝牙设备(包括那些超出范围和已关闭电源的设备)的数组。

语法

js
getDevices()

参数

无。

返回值

一个 Promise,其会兑现为一个 BluetoothDevice 对象数组。

异常

SecurityError DOMException

如果由于安全问题,例如在当前文档的访问被权限策略指令 bluetooth 阻止时调用,则会抛出此异常。

规范

Specification
Web Bluetooth
# dom-bluetooth-getdevices

浏览器兼容性