Web Bluetooth / Availability 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 (Async Await) sample.

Live Output


JavaScript Snippet

navigator.bluetooth.getAvailability()
.then(isBluetoothAvailable => {
  log(`> Bluetooth is ${isBluetoothAvailable ? 'available' : 'unavailable'}`);
});

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