大网数据广告活动
Web 标准与前端开发

Bluetooth: getAvailability() method

· 52CE 我爱测

The **`getAvailability()`** method of the Bluetooth interface _nominally_ returns `true` if the user agent can support Bluetooth (because the device has a Bluetooth adapter), and `false` otherwise.

Bluetooth API

The getAvailability() method of the Bluetooth interface nominally returns true if the user agent can support Bluetooth (because the device has a Bluetooth adapter), and false otherwise.

The word "nominally" is used because if permission to use the Web Bluetooth API is disallowed by the Permissions-Policy: bluetooth permission, the method will always return false. In addition, a user can configure their browser to return false from a getAvailability() call even if the browser does have an operational Bluetooth adapter, and vice versa. This setting value is ignored if access is blocked by the permission.

Even if getAvailability() returns true and the device actually has a Bluetooth adaptor, this does not necessarily mean that calling Bluetooth.requestDevice will resolve with a BluetoothDevice. The Bluetooth adapter may not be powered, and a user might deny permission to use the API when prompted.

Syntax

getAvailability()

Parameters

None.

Return value

A Promise that resolves with a Boolean.

The Promise will resolve with a value of false if access is disallowed by Permissions-Policy: bluetooth, if the user has configured the browser to always resolve with false, or if the device does not have a Bluetooth adapter. Otherwise it will resolve with true.

Exceptions

None.

Examples

The following snippet prints out a message in the console specifying whether or not Bluetooth is supported by the device:

navigator.bluetooth.getAvailability().then((available) => {
  if (available) {
    console.log("This device supports Bluetooth!");
  } else {
    console.log("Doh! Bluetooth is not supported");
  }
});

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。