Is it not possible to use the Web HID API on a Chromebook?

59 views
Skip to first unread message

Vinseam Diver

unread,
Aug 15, 2023, 11:18:03 PM8/15/23
to ChromiumOS Discussion
The following JavaScript code can connect to an HID device using the Vendor ID (VID) and Product ID (PID). However, an exception error (DOMException Notallowed error) occurs when calling device.open
Is it not possible to use the Web HID API on a Chromebook?
Thanks a lot.

let device;

async function connectToDevice() {
  try {
        const devices = await navigator.hid.requestDevice({
        filters: [{ vendorId: 0x1234, productId: 0xABCD }],         
        });
        
        if (devices.length !== 0) {
          console.log('HID device found.');
          device = devices[0];
        } 
  
        // HID Device Connected Already
        if (!device.opened) {
            await device.open();
            console.log('HID device opened successfully.');

  } catch (error) {
    console.error('HID Connection Fail:', error);
  }
}

dragon788

unread,
Aug 16, 2023, 10:16:05 PM8/16/23
to diver...@gmail.com, ChromiumOS Discussion
There are restrictions on the classes of devices allowed to be passed through. Regular HID input devices are only allowed to be accessed by the OS, but joysticks, game controllers, etc can be mapped directly to sites.

if you have a custom HID device that doesn't appear as a keyboard, you'll probably have better luck.

--
--
Chromium OS Discussion mailing list: chromium-...@chromium.org
View archives, change email options, or unsubscribe:
https://groups.google.com/a/chromium.org/group/chromium-os-discuss
---
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-os-dis...@chromium.org.
Reply all
Reply to author
Forward
0 new messages