On mac computer, the oninputreport event has been registered, but the data cannot be received when it is sent for the first time. Only the second time it is sent can the data be received. Continuous one success and one failure
The oninputreport event has been registered, but the data cannot be received when it is sent for the first time. Only the second time it is sent can the data be received. Continuous one success and one failure;
<body>
<button id="fuck">send</button>
</body>
<script>
let requestButton = document.getElementById("fuck");
let device;
requestButton.addEventListener("click", async () => {
try {
const devices = await navigator.hid.requestDevice({
filters: [
{
vendorId: 123,
},
],
});
device = devices[0];
} catch (error) {
console.log("An error occurred.");
}
if (!device) {
console.log("No device was selected.");
} else {
console.log(`HID: ${device.productName}`);
try {
if (!device.opened) {
console.log("open device")
await device.open().then(()=>{
device.oninputreport = ({device, reportId, data}) => {
console.log(`Input report ${reportId} from ${device.productName}:`, new Uint8Array(data.buffer));
};
});
}
const outputReportData = new Uint8Array([0xaa]);
console.log(device);
await device.sendReport(0, outputReportData).then(()=>{
console.log("send success")
});
console.log("Output report sent");
} catch (error) {
console.log("An error occurred.", error)
}
}
});
</script>
</html>
What is the USB device you are connecting to?
Does it work if you set device.oninputreport before calling device.open()?
device.oninputreport = ({device, reportId, data}) => {
console.log(`Input report ${reportId} from ${device.productName}:`, new Uint8Array(data.buffer));
};
await device.open();
What is the USB device you are connecting to?
Does it work if you set
device.oninputreportbefore callingdevice.open()?device.oninputreport = ({device, reportId, data}) => { console.log(`Input report ${reportId} from ${device.productName}:`, new Uint8Array(data.buffer)); }; await device.open();
It is a hardware device developed by ourselves. There is no abnormality in Chrome communication on Windows. This abnormality only occurs on Mac. The first time the data is sent, it cannot be received and returned, only the second time. I tried your way of writing and the result is the same.
Another phenomenon is that when sending for the first time, receiving data fails. The second time you send it, you receive the result of the first time.
@erixyuan I came across an issue that might be related to yours; I'm also running a Mac and have it set up where upon an opening of a device, I have that device that calls a sendReport, which seems to disconnect the device. This is the logic I have:
await device.open();
device.oninputreport = this.handleInputReportEvent;
device.sendReport(REPORT_ID, data);
If the logic runs for the second time, it will not disconnect the device, and the device will remain open.
I tried switching the order for device.open() and device.oninputreport, but that doesn't seem to work. If I remove the sendReport, then the disconnect does not happen and the inputreport events will go through fine the first time.
@shinji-sirona Can you check chrome://device-log and see if anything was logged for HID?
Can you share the HID report descriptor for your device? See here for instructions to get the report descriptor on macOS.
@nondebug I get these logs in the chrome://device-log page (chronologically from bottom to top) when I go through the process of plugging in the device, requesting the device, and connecting the device, and then programmatically calling sendReport (which occurs at around 17:19:37):
USBUser[17:19:39] USB device added: vendor=2321 "Philips Speech Processing", product=3100 "SpeechMike III", serial="", guid=5fc5e92c-d1c7-4e80-8d7a-264491b24fc7
HIDUser[17:19:39] HID device added: vendorId=2321, productId=3100, name='SpeechMike III', serial='', deviceIds=[4306923337], reportDescriptor='BqD/CQGhAQkCoQAGof8JAwkEFYAlfzUARf91CJUJgQIJBQkGFYAlfzUARf91CJUJkQLAwA=='
HIDUser[17:19:39] HID device added: vendorId=2321, productId=3100, name='SpeechMike III', serial='', deviceIds=[4306923335], reportDescriptor='BQEJAqEBCQGhAAUJGQEpAxUAJQGVA3UBgQKVAXUFgQEFAQkwCTEJOBWBJX91CJUDgQbAwA=='
HIDUser[17:19:39] HID device added: vendorId=2321, productId=3100, name='SpeechMike III', serial='', deviceIds=[4306923333], reportDescriptor='BQwJAaEBBQwJ6QUMCeoVACUBlQJ1AYFClQF1BoEBwA=='
HIDUser[17:19:39] HID device added: vendorId=2321, productId=3100, name='SpeechMike III', serial='', deviceIds=[4306923329], reportDescriptor='BQEJBqEBBQcZ4CnnFQAlAZUIdQGBApUBdQiBAZUBdQgVACVlBQcZACllgQDA'
HIDUser[17:19:37] HID device removed: deviceId='4306923191'
HIDUser[17:19:37] HID device removed: deviceId='4306923203'
HIDUser[17:19:37] HID device removed: deviceId='4306923201'
HIDEvent[17:19:37] Failed to close HID device: 0xe00002d7
HIDUser[17:19:37] HID device removed: deviceId='4306923199'
HIDUser[17:19:37] HID device removed: deviceId='4306923194'
USBUser[17:19:37] USB device removed: guid=ef821c08-0249-4f1c-824c-f4a2f6f46aa0
USBUser[17:19:08] USB device added: vendor=2321 "Philips Speech Processing", product=4000 "SpeechMike III", serial="", guid=ef821c08-0249-4f1c-824c-f4a2f6f46aa0
HIDUser[17:19:08] HID device added: vendorId=2321, productId=4000, name='SpeechMike III', serial='', deviceIds=[4306923203], reportDescriptor='BQwJAaEBBQwJ6QUMCeoVACUBlQJ1AYFClQF1BoEBwA=='
HIDUser[17:19:08] HID device added: vendorId=2321, productId=4000, name='SpeechMike III', serial='', deviceIds=[4306923201], reportDescriptor='BQEJBKEBCQGhAAUJGQEpFBUAJQGVFHUBgQKVAXUEgQEFAQkwCTEVgSV/dQiVAoECwMA='
HIDUser[17:19:08] HID device added: vendorId=2321, productId=4000, name='SpeechMike III', serial='', deviceIds=[4306923199], reportDescriptor='BqD/CQGhAQkCoQAGof8JAwkEFYAlfzUARf91CJUJgQIJBQkGFYAlfzUARf91CJUJkQLAwA=='
HIDUser[17:19:08] HID device added: vendorId=2321, productId=4000, name='SpeechMike III', serial='', deviceIds=[4306923194], reportDescriptor='BQEJAqEBCQGhAAUJGQEpAxUAJQGVA3UBgQKVAXUFgQEFAQkwCTEJOBWBJX91CJUDgQbAwA=='
HIDUser[17:19:08] HID device added: vendorId=2321, productId=4000, name='SpeechMike III', serial='', deviceIds=[4306923191], reportDescriptor='BQEJBqEBBQcZ4CnnFQAlAZUIdQGBApUBdQiBAZUBdQgVACVlBQcZACllgQDA'
One thing to note is the sendReport command is to specifically set the button mode on my device from "browser" mode to "event" mode, which seems to cause a disconnect of the device: https://www.dictation.philips.com/fileadmin/Products/smp3700/ifu/en/button-modes.html
Oh, interesting. I'm somewhat familiar with this device but I don't know how it's controlled over HID. Is there some public documentation somewhere?
The disconnect behavior seems intentional. Some USB devices that support different operating modes need to simulate a disconnect to change device details that normally can't be changed while connected.
Here's the logs from before switching modes:
consumer HIDUser[17:19:08] HID device added: vendorId=2321, productId=4000, name='SpeechMike III', serial='', deviceIds=[4306923203], reportDescriptor='BQwJAaEBBQwJ6QUMCeoVACUBlQJ1AYFClQF1BoEBwA==' joystick HIDUser[17:19:08] HID device added: vendorId=2321, productId=4000, name='SpeechMike III', serial='', deviceIds=[4306923201], reportDescriptor='BQEJBKEBCQGhAAUJGQEpFBUAJQGVFHUBgQKVAXUEgQEFAQkwCTEVgSV/dQiVAoECwMA=' vendor-defined HIDUser[17:19:08] HID device added: vendorId=2321, productId=4000, name='SpeechMike III', serial='', deviceIds=[4306923199], reportDescriptor='BqD/CQGhAQkCoQAGof8JAwkEFYAlfzUARf91CJUJgQIJBQkGFYAlfzUARf91CJUJkQLAwA==' mouse HIDUser[17:19:08] HID device added: vendorId=2321, productId=4000, name='SpeechMike III', serial='', deviceIds=[4306923194], reportDescriptor='BQEJAqEBCQGhAAUJGQEpAxUAJQGVA3UBgQKVAXUFgQEFAQkwCTEJOBWBJX91CJUDgQbAwA==' keyboard HIDUser[17:19:08] HID device added: vendorId=2321, productId=4000, name='SpeechMike III', serial='', deviceIds=[4306923191], reportDescriptor='BQEJBqEBBQcZ4CnnFQAlAZUIdQGBApUBdQiBAZUBdQgVACVlBQcZACllgQDA'
This device has five HID interfaces: mouse, keyboard, joystick, consumer, and vendor-defined.
After switching, it has a new product id and only four interfaces:
vendor-defined HIDUser[17:19:39] HID device added: vendorId=2321, productId=3100, name='SpeechMike III', serial='', deviceIds=[4306923337], reportDescriptor='BqD/CQGhAQkCoQAGof8JAwkEFYAlfzUARf91CJUJgQIJBQkGFYAlfzUARf91CJUJkQLAwA==' mouse HIDUser[17:19:39] HID device added: vendorId=2321, productId=3100, name='SpeechMike III', serial='', deviceIds=[4306923335], reportDescriptor='BQEJAqEBCQGhAAUJGQEpAxUAJQGVA3UBgQKVAXUFgQEFAQkwCTEJOBWBJX91CJUDgQbAwA==' consumer HIDUser[17:19:39] HID device added: vendorId=2321, productId=3100, name='SpeechMike III', serial='', deviceIds=[4306923333], reportDescriptor='BQwJAaEBBQwJ6QUMCeoVACUBlQJ1AYFClQF1BoEBwA==' keyboard HIDUser[17:19:39] HID device added: vendorId=2321, productId=3100, name='SpeechMike III', serial='', deviceIds=[4306923329], reportDescriptor='BQEJBqEBBQcZ4CnnFQAlAZUIdQGBApUBdQiBAZUBdQgVACVlBQcZACllgQDA'
The HID interfaces are identical except the joystick interface is missing.
I think this isn't a bug and the device is behaving as expected.
Philips does have some documentation on their SDK here, which seems to be a collaboration with Google: https://www.dictation.philips.com/fileadmin/Products/pcl8010/ifu/en/integrating-philips-dictation-hardware-in-web-based-apps.html
Related github repo: https://github.com/GoogleChromeLabs/dictation_support/tree/main
Also, your hunch seems to be spot on with the expected behavior; there's a demo page that tests the Philips SpeechMike here: https://storage.googleapis.com/chromeos-mgmt-public-extension/dictation_support/index.html
By selecting a mode that is different than the current button mode on the device, a click on setEventMode calls a disconnect on the device, so this seems to be working as intended:
I was hoping that this wasn't the case, as I wanted to have it automatically switch to event mode in case the user had set it to browser mode prior to connecting the device, but I guess I'll have to provide some notification to the user to manually set it.
Thanks @nondebug for helping to debug the issue!