webbluetooth icon indicating copy to clipboard operation
webbluetooth copied to clipboard

getDevices() returns an empty list on Windows 11

Open FLATT-Dev opened this issue 1 year ago • 3 comments

This code

const bluetooth = new Bluetooth({ deviceFound });
const device = await bluetooth.getDevices();

returns an empty list and this message in the console

[INFO] SimpleBLE: D:\a\webbluetooth\webbluetooth\SimpleBLE\simpleble\src\backends\windows\Utils.cpp:33 in initialize_winrt: CoGetApartmentType: cotype=-1, qualifier=0, result=800401F0 [INFO] SimpleBLE: D:\a\webbluetooth\webbluetooth\SimpleBLE\simpleble\src\backends\windows\Utils.cpp:41 in initialize_winrt: RoInitialize: result=0

The PC runs Windows 11 and has a built in Bluetooth adapter Any ideas how to fix? Thank you

FLATT-Dev avatar Aug 15 '24 00:08 FLATT-Dev

If possible, can you see if the underlying bluetooth engine works on your system?

https://github.com/OpenBluetoothToolbox/SimpleBLE

thegecko avatar Aug 15 '24 13:08 thegecko

Unfortunately I'm not set up to do that at the moment so it will take time. Looking at the SimpleBLE supported platforms it says "Windows 10+" but does not explicitly list Windows 11 so I'm suspicious. I'll try on Windows 10 and let you know Thank you!

FLATT-Dev avatar Aug 15 '24 13:08 FLATT-Dev

Windows 10 should work, I test on it :)

thegecko avatar Aug 15 '24 19:08 thegecko

I am able to reproduce, the same code for discovering at least works from the normal navigator bluetooth implementation https://googlechrome.github.io/samples/web-bluetooth/get-devices.html

kilotone avatar Mar 13 '25 00:03 kilotone

I am able to reproduce, the same code for discovering at least works from the normal navigator bluetooth implementation https://googlechrome.github.io/samples/web-bluetooth/get-devices.html

Welp, disregard that, I misunderstood the design pattern and was trying to extend the calls into an emitter pattern. Discovered that You need to call bluetooth.requestdevice to populate the devices, then getDevices()

kilotone avatar Mar 13 '25 00:03 kilotone

Bump! Same happening here.

I did try simplepyble, that also uses SimpleBLE, and worked; but I do need a JS implementation...

DaryeDev avatar Jun 28 '25 22:06 DaryeDev

I need to see some reproducer code for this issue, please

thegecko avatar Jun 30 '25 15:06 thegecko

I need to see some reproducer code for this issue, please

Here is a simple test case.

testCase.zip

chdh avatar Nov 06 '25 04:11 chdh

Hi @FLATT-Dev, I ran @chdh test case with 3.3.2 on Win 11 Pro 24H2 and getDevices() behaves as it should there. See #331. What exact version of Win are you using?

jubesab avatar Nov 06 '25 06:11 jubesab

@jubesab getDevices() returns the devices array. The only place where an entry is added to this array is line 302:

devices.push(bluetoothDevice);

This line is only executed when the condition of the IF statement is met:

if (this.options?.allowAllDevices || this.allowedDevices.has(deviceInfo.id)) {

allowAllDevices is not set in my test case for this issue and the allowedDevices set is empty. I don't understand how this could ever work.

chdh avatar Nov 06 '25 17:11 chdh