Web Bluetooth / Availability (Async Await) Sample

Available in Chrome 78+ | View on GitHub | Browse Samples

The Web Bluetooth API lets websites discover and communicate with devices over the Bluetooth 4 wireless standard using the Generic Attribute Profile (GATT). It is currently partially implemented in Android M, Chrome OS, Mac, and Windows 10.

This sample illustrates the use of the Web Bluetooth API to determine whether Bluetooth is available. You may want to check out the Availability (Promises) sample.

Live Output

JavaScript Snippet

(async () => {
  try {
    const isBluetoothAvailable = await navigator.bluetooth.getAvailability();
    log(`> Bluetooth is ${isBluetoothAvailable ? 'available' : 'unavailable'}`);
  } catch(error) {
    log('Argh! ' + error);

if ('onavailabilitychanged' in navigator.bluetooth) {
  navigator.bluetooth.addEventListener('availabilitychanged', function(event) {
    log(`> Bluetooth is ${event.value ? 'available' : 'unavailable'}`);