Bluetooth.requestDevice()

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

The Bluetooth.requestDevice() method of the Bluetooth interface returns a Promise to a BluetoothDevice object with the specified options. If there is no chooser UI, this method returns the first device matching the criteria.

Syntax

Bluetooth.requestDevice([options])
  .then(function(bluetoothDevice) { ... })

Returns

A Promise to a BluetoothDevice object.

Parameters

options Optional
An object that sets options for the device request. The available options are:
  • filters[]: An array of BluetoothScanFilters. This filter consists of an array of  BluetoothServiceUUIDs, a name parameter, and a namePrefix parameter.
  • optionalServices[]: An array of BluetoothServiceUUIDs.
  • acceptAllDevices: A Boolean indicating that the requesting script can accept all Bluetooth devices. The default is false.

Example

// Discovery options match any devices advertising:
// . The standard heart rate service.
// . Both 16-bit service IDs 0x1802 and 0x1803.
// . A proprietary 128-bit UUID service c48e6067-5295-48d3-8d5c-0395f61792b1.
// . Devices with name "ExampleName".
// . Devices with name starting with "Prefix".
//
// And enables access to the battery service if devices
// include it, even if devices do not advertise that service.
let options = {
  filters: [
    {services: ['heart_rate']},
    {services: [0x1802, 0x1803]},
    {services: ['c48e6067-5295-48d3-8d5c-0395f61792b1']},
    {name: 'ExampleName'},
    {namePrefix: 'Prefix'}
  ],
  optionalServices: ['battery_service']
}

navigator.bluetooth.requestDevice(options).then(function(device) {
  console.log('Name: ' + device.name);
  // Do something with the device.
})
.catch(function(error) {
  console.log("Something went wrong. " + error);
});

Detailed examples are in the specification.

Specifications

Specification Status Comment
Web Bluetooth
The definition of 'requestDevice()' in that specification.
Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic support
Experimental
Chrome Full support 56
Notes
Full support 56
Notes
Notes macOS only.
Full support 56
Notes Disabled
Notes Linux and versions of Windows earlier than 10.
Disabled From version 56: this feature is behind the #enable-experimental-web-platform-features preference (needs to be set to enabled). To change preferences in Chrome, visit chrome://flags.
Full support 70
Notes
Notes Windows 10.
Edge ? Firefox ? IE ? Opera Full support 43
Notes
Full support 43
Notes
Notes macOS only.
Full support 43
Notes Disabled
Notes Linux and versions of Windows earlier than 10.
Disabled From version 43: this feature is behind the #enable-experimental-web-platform-features preference (needs to be set to enabled).
Full support 57
Notes
Notes Windows 10.
Safari ? WebView Android No support NoChrome Android Full support 56Edge Mobile ? Firefox Android ? Opera Android Full support 43Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

Document Tags and Contributors

Contributors to this page: fscholz, jpmedley, styfle, scheib, rolfedh
Last updated by: fscholz,