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