{{APIRef()}}{{SeeCompatTable}}
The Bluetooth.requestDevice()
method of the {{domxref("Bluetooth")}} interface returns a {{jsxref("Promise")}} to a {{domxref("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 {{jsxref("Promise")}} to a {{domxref("BluetoothDevice")}} object.
Parameters
- options
- An object that sets options for the device request. The available options are:
filters[]
: An array ofBluetoothScanFilters
. This filter consists of an array ofBluetoothServiceUUID
s, aname
parameter, and anamePrefix
parameter.optionalServices[]
: An array ofBluetoothServiceUUID
s.
Example
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); });
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('Web Bluetooth', '#dom-bluetooth-requestdevice', 'requestDevice()')}} | {{Spec2('Web Bluetooth')}} | Initial definition. |
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatChrome (45.0)}} [1] |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatChrome (48.0)}} [2] |
[1] Behind a flag. Chrome OS only.
[2] Behind a flag. Requires Android 6 (Marshmallow).