I have found https://github.com/thegecko/webusb - an implementation of WebUSB for nodejs
I haven't quite got my head around how to get this working in the browser?
I have found https://github.com/thegecko/webusb - an implementation of WebUSB for nodejs
I haven't quite got my head around how to get this working in the browser?
You can't use node's implementation of WebUSB on the browser - it only works on node.js. To use WebUSB in the browser you either need it implemented in the browser or somehow implement it as a browser extension.
Currently there are no browser extensions that implement WebUSB. However there are browsers that have implemented WebUSB.
As of today (June 2019) Google Chrome and Opera have implemented WebUSB (both desktop and Android). You don't need any additional library, just start using it.
The following code will produce a popup asking permission to connect to a USB device on browsers that support WebUSB:
<html>
<body>
<button id="usb">Connect to a USB Device</button>
<script>
document.getElementById('usb').addEventListener('click',function(){
if (navigator.usb) {
navigator.usb.requestDevice({
filters: []
})
.then(function(device){
document.body.innerHTML +=
device.manufacturerName + ', ' +
device.productName;
});
}
});
</script>
</body>
</html>
For now, if you want to use WebUSB you need to tell your users to use Chrome or Opera.