Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Web Bluetooth PIN pairing fails on Windows #33111

Closed
3 tasks done
gniezen opened this issue Mar 1, 2022 · 12 comments · Fixed by #35416
Closed
3 tasks done

[Bug]: Web Bluetooth PIN pairing fails on Windows #33111

gniezen opened this issue Mar 1, 2022 · 12 comments · Fixed by #35416

Comments

@gniezen
Copy link
Contributor

gniezen commented Mar 1, 2022

Preflight Checklist

Electron Version

17.0.1

What operating system are you using?

Windows

Operating System Version

Windows 10 Pro 1909

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

When pairing a device using the Web Bluetooth API that requires a PIN, I expect the PIN pairing dialog box to appear.

Actual Behavior

PIN pairing dialog box does not appear, and operation fails with "GATT error: Not paired."

Testcase Gist URL

No response

Additional Information

Web Bluetooth PIN pairing has always worked on MacOS, but there was a Chromium bug that prevented it from working on Windows. This bug has since been fixed, at least since Chromium v96.0.4664.110.

@gniezen
Copy link
Contributor Author

gniezen commented Mar 10, 2022

@jkleinsc Anything else I can do to help with this?

@gniezen
Copy link
Contributor Author

gniezen commented Jul 14, 2022

@jkleinsc @dsanders11 @codebytere It looks like this also affects devices that pair without a PIN, and still exists on Electron v19. Please let me know if there's anything I can do to help move this forward or make it easier to debug.

@jkleinsc
Copy link
Contributor

@gniezen I have a fix about ready to go but I was wondering if you know of any specific devices to test with?

@jkleinsc
Copy link
Contributor

@gniezen I see this linked issue: tidepool-org/uploader#1515. Will this device work to test the issue: https://www.walmart.com/ip/Contour-Next-ONE-Blood-Glucose-Monitoring-System-Value-Pack/278244026 ?

@gniezen
Copy link
Contributor Author

gniezen commented Aug 23, 2022

Hi @jkleinsc ! Yes, the Contour Next One meter will definitely work to test with. Here's how to put it in pairing mode:

image

Here is where it currently fails in my code:

this.server = await this.device.gatt.connect();

this.deviceInfoService = await this.server.getPrimaryService('device_information');
this.glucoseService = await this.server.getPrimaryService('glucose');

const glucoseFeature = await this.glucoseService.getCharacteristic('glucose_feature');
const features = await glucoseFeature.readValue();

I can connect to the device, but when I try to read the protected characteristic, I expect to have to enter the pairing PIN. Instead it returns an error like NetworkError: Connection failed for unknown reason. or GATT error: Not paired.

@jkleinsc
Copy link
Contributor

@gniezen I have been testing #35416 with the Contour Next One meter on Windows 11 and it looks like that particular device does not require a pairing PIN. I verified this by testing in Chrome and Edge using https://googlechrome.github.io/samples/web-bluetooth/get-characteristics.html to test. Both browsers never prompted for a pin but they were able to successfully get the glucose_feature characteristic.

Electron does throw an error calling const features = await glucoseFeature.readValue(); but if I first pair the Contour Next One meter with Windows via the OS prompt, Electron can then successfully call const features = await glucoseFeature.readValue();. I've debugged this further and the error is at the OS level, so I'm not sure how we can fix that and/or why Edge and Chrome don't need the device paired at the OS first. It's possible that Edge and Chrome have a security exception that Electron does not.

@jkleinsc
Copy link
Contributor

@gniezen - I think maybe my Electron test was doing something wrong, because when I run the code from https://googlechrome.github.io/samples/web-bluetooth/get-characteristics.html in Electron with the build from #35416, it works with errors. So I believe #35416 should resolve your issue.

@gniezen
Copy link
Contributor Author

gniezen commented Aug 26, 2022

@jkleinsc It looks like even though the Contour Next One meter does allow for PIN pairing, it can also use Just Works pairing, so it doesn't necessarily require the PIN pairing dialog box. Sorry, I should've checked this in more detail. When I use a meter that does require a PIN (e.g. the Accu-chek Guide Me) the browser shows this screen:

image

I agree that #35416 should resolve the issue. Please let me know when there's a build available that I can test!

@gniezen
Copy link
Contributor Author

gniezen commented Sep 7, 2022

@jkleinsc I was just looking into this again and realised support for confirm-only support only became available in Chrome v105.0.5195.68, and is still hidden behind a flag #enable-web-bluetooth-confirm-pairing-support:

https://bugs.chromium.org/p/chromium/issues/detail?id=1309715

@gniezen
Copy link
Contributor Author

gniezen commented Nov 28, 2022

@jkleinsc I can't seem to get any devices that use confirm-only PIN pairing to work. Should I file a new bug report?

@jkleinsc
Copy link
Contributor

jkleinsc commented Nov 29, 2022

@gniezen I think the PIN pairing requires the enable-web-bluetooth-confirm-pairing-support flag to be set (it is still disabled by default), which you can do via:

app.commandLine.appendSwitch('--enable-features=WebBluetoothConfirmPairingSupport')

If that fails to work, feel free to open up a new issue with a reproducible test case.

@gniezen
Copy link
Contributor Author

gniezen commented Nov 30, 2022

Thanks @jkleinsc , I got it working! 🎉 I previously had app.commandLine.appendSwitch('enable-web-bluetooth-confirm-pairing-support', true); which is not correct. I then used your suggestion, but it still didn't work because I had another line later (app.commandLine.appendSwitch('enable-features', 'SharedArrayBuffer');) that overwrote the previous switch settings, so in my case the solution was

app.commandLine.appendSwitch('enable-features', 'SharedArrayBuffer,WebBluetoothConfirmPairingSupport');

Thank you so much - it's such a relief to be able to support Bluetooth PIN/confirm pairing on Windows!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants