WICG / serial

Serial ports API for the platform.
https://wicg.github.io/serial/
Other
255 stars 48 forks source link

Falling back to WebUSB user-space drivers on MacOS #204

Open gniezen opened 3 months ago

gniezen commented 3 months ago

On MacOS it is becoming more and more difficult to install kernel extensions, and their successor since Catalina, driver extensions. It can also be challenging to get a DriverKit entitlement in order to write a driver extension. Apple includes built-in kernel/driver extensions for a number of chipsets, but not all, and these also don't work if the device has a custom USB PID/VID.

Luckily, if there is no existing USB serial port driver installed, MacOS will load the default USB driver, which can be accessed over WebUSB. I have written a bunch of JS user-space drivers for FTDI, Texas Instruments, Silicon Labs and Prolific chipsets, and these work well as a fallback mechanism.

However, It does lead to a confusing user experience, where we first have to display the Web Serial permission prompt in case there is a USB driver already installed, and then display the WebUSB permission prompt when the user presses Cancel (as the Web Serial API doesn't find any devices) so that we can then connect using WebUSB instead.

Could there be away to make Web Serial a little bit more aware of WebUSB, for example by providing a new method that would automatically fall back to navigator.usb.requestDevice when navigator.serial.requestPort comes up empty?

reillyeon commented 3 months ago

There's an issue on the WebUSB side tracking this: https://github.com/WICG/webusb/issues/186

gniezen commented 3 months ago

Ah, that's great, thanks @reillyeon ! I should probably have checked there first, but at least now we have issues on both repos tracking this. How can I help move this forward?

reillyeon commented 3 months ago

The challenge is mainly on the implementation side. There's platform-specific work necessary to make sure we're modeling the device relationships correctly between the platform USB, serial and HID APIs. It's something that's on our team's roadmap but I can't make any promises on when we'll be able to deliver it.