chrome.bluetooth

Description: Use the chrome.bluetooth API to connect to a Bluetooth device. All functions report failures via chrome.runtime.lastError.
Availability: Since Chrome 37.
Manifest: "bluetooth": {...}
Learn More: Bluetooth

Important: This API works only on OS X, Windows and Chrome OS.

Summary

Types
AdapterState
Device
Methods
getAdapterState chrome.bluetooth.getAdapterState(function callback)
getDevice chrome.bluetooth.getDevice(string deviceAddress, function callback)
getDevices chrome.bluetooth.getDevices(object filter, function callback)
startDiscovery chrome.bluetooth.startDiscovery(function callback)
stopDiscovery chrome.bluetooth.stopDiscovery(function callback)
Events
onAdapterStateChanged
onDeviceAdded
onDeviceChanged
onDeviceRemoved

Types

AdapterState

properties
string address

The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'.

string name

The human-readable name of the adapter.

boolean powered

Indicates whether or not the adapter has power.

boolean available

Indicates whether or not the adapter is available (i.e. enabled).

boolean discovering

Indicates whether or not the adapter is currently discovering.

Device

properties
string address

The address of the device, in the format 'XX:XX:XX:XX:XX:XX'.

string (optional) name

The human-readable name of the device.

integer (optional) deviceClass

The class of the device, a bit-field defined by http://www.bluetooth.org/en-us/specification/assigned-numbers/baseband.

enum of "bluetooth", or "usb" (optional) vendorIdSource

The Device ID record of the device, where available.

integer (optional) vendorId
integer (optional) productId
integer (optional) deviceId
enum of "computer", "phone", "modem", "audio", "carAudio", "video", "peripheral", "joystick", "gamepad", "keyboard", "mouse", "tablet", or "keyboardMouseCombo" (optional) type

The type of the device, if recognized by Chrome. This is obtained from the |deviceClass| field and only represents a small fraction of the possible device types. When in doubt you should use the |deviceClass| field directly.

boolean (optional) paired

Indicates whether or not the device is paired with the system.

boolean (optional) connected

Indicates whether the device is currently connected to the system.

boolean (optional) connecting

Since Chrome 48.

Indicates whether the device is currently connecting to the system.

boolean (optional) connectable

Since Chrome 48.

Indicates whether the device is connectable.

array of string (optional) uuids

UUIDs of protocols, profiles and services advertised by the device. For classic Bluetooth devices, this list is obtained from EIR data and SDP tables. For Low Energy devices, this list is obtained from AD and GATT primary services. For dual mode devices this may be obtained from both.

integer (optional) inquiryRssi

Since Chrome 44.

The received signal strength, in dBm. This field is avaliable and valid only during discovery. Outside of discovery it's value is not specified.

integer (optional) inquiryTxPower

Since Chrome 44.

The transmitted power level. This field is avaliable only for LE devices that include this field in AD. It is avaliable and valid only during discovery.

enum of "invalid", "classic", "le", or "dual" (optional) transport

Since Chrome 76.

The transport type of the bluetooth device.

integer (optional) batteryPercentage

Since Chrome 77.

The remaining battery of the device. TODO(https://crbug.com/973237): This field is only used by Chrome OS and it is different from others because it is not filled by the platform. In the future, when there is a unified Mojo service, this field will be moved to BluetoothDeviceInfo.

Methods

getAdapterState

chrome.bluetooth.getAdapterState(function callback)

Get information about the Bluetooth adapter.

Parameters
function callback

Called with an AdapterState object describing the adapter state.

The callback parameter should be a function that looks like this:

function( AdapterState adapterInfo) {...};
AdapterState adapterInfo

Object containing the adapter information.

getDevice

chrome.bluetooth.getDevice(string deviceAddress, function callback)

Get information about a Bluetooth device known to the system.

Parameters
string deviceAddress

Address of device to get.

function callback

Called with the Device object describing the device.

The callback parameter should be a function that looks like this:

function( Device deviceInfo) {...};
Device deviceInfo

Object containing the device information.

getDevices

chrome.bluetooth.getDevices(object filter, function callback)

Get a list of Bluetooth devices known to the system, including paired and recently discovered devices.

Parameters
object (optional) filter

Since Chrome 67.

Some criteria to filter the list of returned bluetooth devices. If the filter is not set or set to {}, returned device list will contain all bluetooth devices. Right now this is only supported in ChromeOS, for other platforms, a full list is returned.

enum of "all", or "known" (optional) filterType

Type of filter to apply to the device list. Default is all.

integer (optional) limit

Maximum number of bluetoth devices to return. Default is 0 (no limit) if unspecified.

function callback

Called when the search is completed.

The callback parameter should be a function that looks like this:

function(array of Device deviceInfos) {...};
array of Device deviceInfos

Array of object containing device information.

startDiscovery

chrome.bluetooth.startDiscovery(function callback)

Start discovery. Newly discovered devices will be returned via the onDeviceAdded event. Previously discovered devices already known to the adapter must be obtained using getDevices and will only be updated using the |onDeviceChanged| event if information about them changes.

Discovery will fail to start if this application has already called startDiscovery. Discovery can be resource intensive: stopDiscovery should be called as soon as possible.

Parameters
function (optional) callback

Called to indicate success or failure.

If you specify the callback parameter, it should be a function that looks like this:

function() {...};

stopDiscovery

chrome.bluetooth.stopDiscovery(function callback)

Stop discovery.

Parameters
function (optional) callback

Called to indicate success or failure.

If you specify the callback parameter, it should be a function that looks like this:

function() {...};

Events

onAdapterStateChanged

Fired when the state of the Bluetooth adapter changes.

addListener

chrome.bluetooth.onAdapterStateChanged.addListener(function callback)
Parameters
function callback

The callback parameter should be a function that looks like this:

function( AdapterState state) {...};
AdapterState state

The new state of the adapter.

onDeviceAdded

Fired when information about a new Bluetooth device is available.

addListener

chrome.bluetooth.onDeviceAdded.addListener(function callback)
Parameters
function callback

The callback parameter should be a function that looks like this:

function( Device device) {...};
Device device

onDeviceChanged

Fired when information about a known Bluetooth device has changed.

addListener

chrome.bluetooth.onDeviceChanged.addListener(function callback)
Parameters
function callback

The callback parameter should be a function that looks like this:

function( Device device) {...};
Device device

onDeviceRemoved

Fired when a Bluetooth device that was previously discovered has been out of range for long enough to be considered unavailable again, and when a paired device is removed.

addListener

chrome.bluetooth.onDeviceRemoved.addListener(function callback)
Parameters
function callback

The callback parameter should be a function that looks like this:

function( Device device) {...};
Device device