The WebUSB API provides a USBDevice
interface which is returned by navigator.usb.getDevices()
and navigator.usb.requestDevice()
. This interface has methods equivalent to all but one of those listed above:
chrome.usb.releaseInterface() -> releaseInterface()
chrome.usb.closeDevice() -> close()
chrome.usb.claimInterface() -> claimInterface()
chrome.usb.bulkTransfer() -> transferIn() or transferOut().
chrome.usb.findDevices()
is more complex to replace and first requires explaining the differences between the permission model for the WebUSB API and the chrome.usb API. The WebUSB API does not provide an install-time permission to access USB devices. A site must call navigator.usb.requestDevice()
to ask the user for permission to access new USB devices. For devices with serial numbers permissions are remembered and so you can call navigator.usb.getDevices()
to get a list of currently connected devices a site previously got permission to access. This is the same model as the chrome.usb.getUserSelectedDevices()
function. The chrome.usb.findDevices()
function also implicitly opened the devices in the process of returning them to the application. There is no equivalent to this behavior. The site must explicitly call open()
on the USBDevice
interfaces returned by these methods.
Note, that if this application is being deployed into a managed environment the WebUsbAllowDevicesForUrls policy can be used to mimic the Chrome Apps permission model. Devices allowed by policy will be returned by navigator.usb.getDevices()
without the need to call navigator.usb.requestDevice()
and prompt the user first.