1

Is it possible to "silently"(without calling navigator.hid.requestDevice) reconnect hid device after it was disconnected and connected with USB cable again?

navigator.hid.getDevices is not an option, it doesn't return device after it was disconnected.

Igor Alemasow
  • 4,484
  • 2
  • 27
  • 24

2 Answers2

3

Assuming that the device has a serial number so that the browser can recognize it when it reconnects and match it against the permission previously granted by the user then it should be returned by navigator.hid.getDevices().

There is an open Chromium issue tracking a potential regression in this behavior. Please CC yourself on that issue to track the fix.

Reilly Grant
  • 5,590
  • 1
  • 13
  • 23
  • Hi can you answer this question please https://stackoverflow.com/questions/63775442/how-to-get-picture-from-a-camera-in-browser-using-web-usb-api – gANDALF Sep 07 '20 at 10:07
0

Try subscribing to the connection event, like so:

navigator.hid.addEventListener("connect", (ev) => {
  if (ev.device.productId === product_id) {
    // You have the device now. You can open it, subscribe to reports, 
    //   or whatever your application requires
    ev.device.open();
  }
});