Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1026322 of Bluetooth.requestDevice()

  • Revision slug: Web/API/Bluetooth/requestDevice
  • Revision title: Bluetooth.requestDevice()
  • Revision id: 1026322
  • Created:
  • Creator: rolfedh
  • Is current revision? Yes
  • Comment Editorial review. No changes.

Revision Content

{{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 of BluetoothScanFilters. This filter consists of an array of  BluetoothServiceUUIDs, a name parameter, and a namePrefix parameter.
  • optionalServices[]: An array of BluetoothServiceUUIDs.

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

Revision Source

<p>{{APIRef()}}{{SeeCompatTable}}</p>

<p>The <strong><code>Bluetooth.requestDevice()</code></strong> method of the {{domxref("Bluetooth")}} interface returns&nbsp;a {{jsxref("Promise")}}&nbsp;to&nbsp;a {{domxref("BluetoothDevice")}}&nbsp;object with the specified options. If there is no chooser UI, this method returns the first device matching the criteria.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
Bluetooth.requestDevice(options).then(function(bluetoothDevice) { ... })</pre>

<h3 id="Returns">Returns</h3>

<p>A {{jsxref("Promise")}}&nbsp;to&nbsp;a {{domxref("BluetoothDevice")}}&nbsp;object.</p>

<h3 id="Parameters">Parameters</h3>

<dl>
 <dt>options&nbsp;</dt>
 <dd>An object that sets&nbsp;options for the device request.&nbsp;The available options are:
 <ul>
  <li><code>filters[]</code>: An array of <code>BluetoothScanFilters</code>. This filter consists of an array of&nbsp; <code>BluetoothServiceUUID</code>s, a <code>name</code> parameter, and a <code>namePrefix</code> parameter.</li>
  <li><code>optionalServices[]</code>: An array of <code>BluetoothServiceUUID</code>s.</li>
 </ul>
 </dd>
</dl>

<h2 id="Example">Example</h2>

<pre class="brush: js">
navigator.bluetooth.requestDevice(options).then(function(device) {
&nbsp; console.log('Name: ' + device.name);
&nbsp; // Do something with the device.
})
.catch(function(error) {
&nbsp; console.log("Something went wrong. " + error);
});
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Web Bluetooth', '#dom-bluetooth-requestdevice', 'requestDevice()')}}</td>
   <td>{{Spec2('Web Bluetooth')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome (45.0)}} [1]</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>{{CompatChrome (48.0)}} [2]</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Behind a flag. Chrome OS only.</p>

<p>[2] Behind a flag. Requires&nbsp;Android 6 (Marshmallow).</p>
Revert to this revision