MENU
WebUSB
The WebUSB API finds and connects USB devices from a web page.
Note: this is an experimental technology which may not work in some environments.RESETRUNFULL
const filters = [{vendorId: 0x1209, productId: 0xa800},
{vendorId: 0x1209, productId: 0xa850}];
navigator.usb.requestDevice({filters: filters}).then(usbDevice => {
console.log("Product name: " + usbDevice.productName);
}).catch(e => {
console.log("There is no device. " + e);
});
navigator.usb.onconnect = ()=>{};
navigator.usb.ondisconnect = ()=>{};
<!DOCTYPE html><html><body>
<button onclick="connectUSB()">Connect Bluetooth</button>
<script>
function connectUSB(){
navigator.usb.getDevices().then(devices => {
console.log("Total devices: " + devices.length);
devices.forEach(device => {console.log("Product name: " + device.productName + ", serial number " + device.serialNumber); });
});
}
</script></body></html>
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.