usbwebusb

Can webusb automatically connect without user-gesture, when device has no serial number?


I am writing a web-app, where my users use, a DS2490 ibutton reader, zebra scanner, zebra printer and Loadstar di1000 Loadcell. I run chrome os flex on the devices, that run this webapp, and i manage them via the google admin console. I am using the following policies: WebUsbAllowDevicesForUrls, UsbDetachableAllowlist, to give the web-app access to the usb devices

All devices, but the ibutton reader connect automatically, when the page is loaded.

I found this post, where the asker had kind of the same problem as me. It looks like the problem was that his custom usb device didn't have a serial number, and he solved it by giving it a one. When i look at the usb data of the ibutton reader, it shows that the serial number string is empty. Can the lack of a serial number have anything to do with the device not automatically connecting?

the post: How to re-connect to USB device without user gesture?

Connect function:

  async connect(e) {
    try {
      this.device = await navigator.usb.requestDevice(this.requestParams);
    }
    catch (e) {
      console.log(e);
      let devices = await navigator.usb.getDevices();
      devices.forEach((element) => {
        if (element.vendorId == this.deviceFilter.vendorId && element.productId == this.deviceFilter.productId) {
          this.device = element
        }
      });
    }
    if (this.device) {
      this.eventTarget.dispatchEvent(new Event('connect'));
      await this.device.open();
      await this.device.selectConfiguration(1);
      await this.device.claimInterface(0);
      this.connected = true
      this.eventTarget.dispatchEvent(new Event('open'));
      this.search = true
      this.searchLoop()
    } else {
    }
  }

Solution

  • That seems like a bug or user error. Make sure you have the vendor and product IDs set correctly for all the devices you want to get permission for by policy. The policy-based permission logic does not require the device to have a serial number.

    If you are using Web Serial or WebHID for some of these devices note that they use different policies, SerialAllowUsbDevicesForUrls and WebHidAllowDevicesForUrls. Please reach out to your Enterprise support representative if you can't find these policies in the Admin Console.

    Note: You probably don't need to set the UsbDetachableAllowlist policy unless one of those devices have a driver that automatically attaches when the device is connected.