WebHID API: reconnect device

855 views Asked by At

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.

2

There are 2 answers

1
Reilly Grant On BEST ANSWER

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.

0
QuillFancyson On

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();
  }
});