webble is a client-side utility which facilitates pairing and exchanging data with BLE devices using the Web Bluetooth API.
webble is lightweight client-side JavaScript that runs in the browser. See a live demo using the code in this repository at: reelyactive.github.io/webble
Include in an index.html file the webble.js script:
<html>
<head></head>
<body>
<button id="startbutton"> Start </button>
<script src="js/webble.js"></script>
<script src="js/app.js"></script>
</body>
</html>
Include in a js/app.js the code to connect to a Bluetooth Low Energy device using webble:
const REQUEST_OPTIONS = { acceptAllDevices: true };
startbutton.addEventListener('click', () => {
webble.requestDeviceAndConnect(REQUEST_OPTIONS, (error) => {
/* Read and write characteristics, etc. */
});
});
Open the index.html file in a web browser and click Start for webble to begin scanning for Bluetooth Low Energy devices in range.
webble supports the following functions which are essentially convenience wrappers around a subset of the Web Bluetooth API methods, using callbacks rather than Promises.
webble.isAvailable((isAvailable) => {
if(isAvailable) { /* Web Bluetooth is supported by this browser */ }
else { /* Web Bluetooth is NOT supported by this browser */ }
});
const REQUEST_OPTIONS = { /* See below */ };
webble.requestDeviceAndConnect(REQUEST_OPTIONS, (error) => {
if(error) { /* The connection was unsuccessful */ }
else { /* webble.device is connected */ }
});
For a complete definition of REQUEST_OPTIONS, see the MDN web docs for requestDevice().
webble.on('connect', (device) => {});
webble.on('disconnect', () => {});
webble.discoverServicesAndCharacteristics((error) => {
if(!error) {
/* webble.device.services and webble.device.characteristics populated */
}
});
let uuid = '6e400001-b5a3-f393-e0a9-e50e24dcca9e';
webble.readCharacteristic(uuid, (error, value) => {
if(!error) { /* value is a DataView */ }
});
let uuid = '6e400001-b5a3-f393-e0a9-e50e24dcca9e';
let value = Uint8Array.of(123); // Value must be a typed array
webble.writeCharacteristic(uuid, value, (error) => {
if(!error) { /* Characteristic write successful */ }
});
webble.disconnect();
Variable | Type | Description |
---|---|---|
webble.device |
Object | Subset of BluetoothDevice, adding services & characteristics, each as a Map |
Discover how to contribute to this open source project which upholds a standard code of conduct.
Consult our security policy for best practices using this open source software and to report vulnerabilities.
MIT License
Copyright (c) 2025 reelyActive
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.