Bluetooth: getAvailability() method

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

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 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 navigator.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

js
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:

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

Specifications

Specification
Web Bluetooth
# dom-bluetooth-getavailability

Browser compatibility

BCD tables only load in the browser