electron: [Bug]: WebUSB API device list is always empty (attached devices are ignored).

Preflight Checklist

Electron Version

23.0.0-alpha.1

What operating system are you using?

macOS

Operating System Version

Ventura 13.0.1

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

No response

Expected Behavior

Electron should detect my Novation Launchpad X (a class-compliant, USB MIDI device).

Actual Behavior

The device shows up in chrome://usb-internals (in stock Chrome), but when I call navigator.usb.getDevices in Electron, the device does not appear in the device list.

The device list is always empty.

Testcase Gist URL

No response

Additional Information

Codewise, I basically have this in my index.js file:

const { app, BrowserWindow } = require("electron");

app.whenReady().then(function() {

    const selectDevice = function(event, details, callback) {
        console.log("device list:", details.deviceList); // this array is always empty
        event.preventDefault();
    };

    const renderer = new BrowserWindow(options); // note: `options` is defined IRL
    renderer.webContents.session.setPermissionCheckHandler(() => true);
    renderer.webContents.session.on("select-usb-device", selectDevice);
});

In the renderer process, I just have a call to navigator.usb.requestDevice (inside a keydown event listener that only exists to ensure that the call is in response to a user gesture).

Note: The filters I’m passing to the WebUSB API are empty (though I tried Novation’s ID (0x1235) too).

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 31 (8 by maintainers)

Most upvoted comments

@desyatirikov @7ombie ignore my comment above… I was also looking at a Bluetooth issue and forgot this was a WebUSB issue.

@bochenev - Thanks. I’ll look into it. I’m on Mac, but it’s hopefully related. Much appreciated.

@7ombie I have the same issue. But I accidentally found solution( on Linux): the problem was with permissions to /dev/bus/usb/ So after change access rights to 777 it is works(wrong way, of course)

@parkerlreed - Nope. There’s no popup. However, I was under the impression that Electron doesn’t use the popup (the permission/device-selection dialog that Chrome uses on the Web). Electron has its own API that we can use to implement a dialog, or we can just go ahead a talk to the device.

I’m not sure how that’s supposed to work when Electron is rendering standards-compliant webapps (not Electron apps), but IIUC, Electron use the same approach for the WebHID, WebBlueTooth, WebUSB and WebSerial APIs.