Search code examples
bluetoothbluetooth-lowenergyweb-bluetooth

Web Bluetooth: Want to filter on manufacturer data when using navigator.bluetooth.requestDevice


I see that Google Chrome has not implemented filtering on manufacturer data. Issue 707635, does not seem to have any progress.

The Web Bluetooth specification has an (unstable) spec for filtering manufacturerData when using navigator.bluetooth.requestDevice (https://webbluetoothcg.github.io/web-bluetooth/#example-filter-by-manufacturer-service-data

Does anyone know if there is any progress on this or made this kind of filtering work?


Solution

  • Following our discussion, I've added support for manufacturer data filter in Web Bluetooth in Chrome 92. See https://crbug.com/707635

    Here's an example:

    // Filter Bluetooth devices from Google company with manufacturer data bytes
    // that start with [0x01, 0x02].
    navigator.bluetooth.requestDevice({
      filters: [{
        manufacturerData: [{
          companyIdentifier: 0x00e0,
          dataPrefix: new Uint8Array([0x01, 0x02])
        }]
      }],
      optionalServices: ['battery_service'] // Required to access service later.
    })
    .then(device => { /* … */ })
    .catch(error => { console.error(error); });
    

    You'll find a sample at https://googlechrome.github.io/samples/web-bluetooth/manufacturer-data-filter.html and some developer documentation at https://web.dev/bluetooth/#manufacturer-data-filter

    Let me know if that works for you ;)