Is there Javascript based mechanism with which i can detect, through a browser, that a user has a specific usb device plugged in?
Asked
Active
Viewed 8,161 times
3
-
3short answer: no. That would be a hacker's dream – Rhumborl Oct 24 '14 at 19:17
-
no, the browser does not expose such information about the machine it's on. – DLeh Oct 24 '14 at 19:20
2 Answers
5
For security reasons, JavaScript in web browsers provides only restricted access to computer resources. It is not possible to store files in an arbitrary folder, start applications or communicate with a USB device.
But there are some exceptions :
- In legacy browsers such as IE6 ~ IE8 you can use ActiveX objects or Java applets to achieve this .
- Use a chrome.usb API .
- Write a browser plugin using NPAPI , (Here, it is not for long though)
2023 Edit
The USB interface of the WebUSB API provides attributes and methods for finding and connecting USB devices from a web page.
( browser support is still limited, for more information refer to browser compatibility table )
Example code:
navigator.usb.getDevices().then((devices) => {
console.log(`Total devices: ${devices.length}`);
devices.forEach((device) => {
console.log(
`Product name: ${device.productName}, serial number ${device.serialNumber}`
);
});
});

Alexander
- 12,424
- 5
- 59
- 76
-
-
Yes, this API provides access to USB operations from within the context of an app. – Alexander Oct 27 '14 at 13:41
2
Your javascript code is sand boxed and therefore cannot access system resources such as usb devices.
I think the only way to access the USB devices would be to write a browser plugin. How to get USB devices List from Browser