Web Bluetooth on Chromium Debian SID – The Saga

If you are following my posts probably you saw my latest post about how to run Web Bluetooth on Chrome/Chromium:

Although in that post I got the Web Bluetooth working on Chrome/Chromium browser, I noted that after closing the browser and opening again the “get characteristic” sample was not able to list the BLE Device’s Characteristics again:

Also I observed that after removing the bluez cache (entering in bluetoothctl and executing a “remove XX:YY:ZZ:KK:WW:AA”) the get characteristics sample was enable to list it again.

Then I worked with François Beaufort (a Google Chromium’s Developer) to figure-out what was going on. François was not facing this issue, because he uses a Chromebook powered by ChromeOS. At that moment we didn’t realize that even closing the sample page’s tab the Chromium keep running because it is the heart of ChromeOS. Later François discovered that if he “Sign out” and “Sign in” this issue also will affect him.

Initially we thought it could be some bug in the BlueZ 5.40, maybe bluez was not sending the data when it was cached. But we also discovered that after closing the browser if I issue a connection to device in bluetoothctl (“connect XX:YY:ZZ:KK:WW:AA”) and open the browser, then the get characteristics sample will work again. So it was not a fail of bluez to send cached data.

We decided to contact Luiz von Dentz (Bluez developer at Intel) at #bluez-users IRC channel and he figured out the issue:

vudentz: if (!IsGattServicesDiscoveryComplete()) {
vudentz:     VLOG(2) << "Gatt services have not been fully
resolved for device " << object_path_.value();
vudentz:     return;
vudentz:   }

vudentz: This is probably false if the device is disconnected since
ServicesResolved: no in that case
vudentz: This would explain why it is not enumerating the service on

vudentz:   // Notify on the discovery complete for each service
which is found in the
vudentz:   // first discovery.
vudentz:   DCHECK(adapter());
vudentz:   for (const auto& iter : gatt_services_)
vudentz:     adapter()->NotifyGattDiscoveryComplete(iter.second);
vudentz: This was also not in the original patch, why would we notify
on the InitializeGattServiceMap, there should be any client waiting for it

François was very kind and helpful instructing me to create many debug log to help him, his team and Luiz to debug the issue. Without his patience and dedication we couldn’t find a solution so fast. Thank you François!

The issue was fixed in the BlueZ 5.41 and latest chromium build.
Patch that was applied is https://codereview.chromium.org/2105423003

More info: