I wrote a chrome extension that is intended to collaborate with a custom hardware device I designed. The problem is, the extension uses a key listener injects a script, but i only want the script to fire if the hardware is plugged in. Is this possible?
Related
I am doing some research on the WebUSB API for our company because we are going to start to manufacture devices in house.
Our current device manufacture comes with an application so the team can plug the device into a computer and diagnose it. Their application allows us to read outputs from the device, as well as pushing commands/configuration to the device over a wired connection.
Since this device is 100% ours, we are also responsible for building out the diagnostic tooling. We need some sort of interface that allows a user to read outputs and send commands/configuration to the device over a wired USB connection.
Is the webUSB the correct API? If not, what are some suggestions for accomplishing the requirement? Are we limited to building some sort of desktop or mobile application?
I would recommend resources below to read to help you understand if the WebUSB API fits your needs or not:
https://web.dev/devices-introduction/ helps you pick the appropriate API to communicate with a hardware device of your choice.
https://web.dev/build-for-webusb/ explains how to build a device to take full advantage of the WebUSB API.
From what you describe, WebUSB isn't strictly required but won't hurt either.
First and foremost, you will need to implement the USB interfaces reading data and sending configurations. It will be a custom protocol, and not one of the standard USB device classes such as HID, video or mass storage. The details of the protocol and if you use control, interrupt or bulk transfers is your choice.
I'm assuming you will connect the devices to Windows PCs, and you likely don't want to put money into writing device drivers. If so, the easiest approach is to add the required descriptors and control requests required for Microsoft OS 2.0 Descriptors. That way, the WinUSB driver will be installed automatically when the device is plugged in.
Using the WinUSB API, a Windows application will then be able to communicate with the USB device. No additional drivers are needed. (On macOS and Linux it's even easier as you don't need the Microsoft OS 2.0 Descriptors in the first place.)
On top of that you can implement the additional descriptors and control requests for WebUSB. It will provide the additional benefit that you can write a web application (instead of a native application) for communicating with the USB device. (Currently, you are restricted to the Chrome browser.) WebUSB devices should implement the WinUSB descriptors as the alternative (.INF files, manual installation process) is a pain.
The already mentioned web page https://web.dev/build-for-webusb/ is a complete example of how to implement it.
Assumptions:
All web browsers can already talk to HID devices with JavaScript
A web browser will not tell the user when some JavaScript code is talking to a HID device
WebUSB is a JavaScript library.
Are my assumptions correct here? Or, have I missed something?
I ask this question because WebUSB claims that it will make USB communication safer. But, I have to wonder how safe USB communication can ever be if the user does not know if/when it is happening. My understanding is that right now, a website can talk to a USB device, and the browser does not have to tell the user that this is happening.
WebUSB looks like it will makes things safer because the user will be guided to a safe website, with a safe interface and so on, but it doesn't seem to me as though it solves the gaping problem where a malicious website can hit your USB device without you ever knowing. Am I wrong?
Browsers do not normally talk to HID devices directly but instead go through the operating system's input API which abstracts away both the HID and USB layers in order to provide higher-level events such as key-down or mouse-move. There may be some exceptions to this for exotic HID devices such as gamepads. Nevertheless the browser is not using JavaScript for these devices but the native system API.
Due to the above the concept of "JavaScript talking to a HID device" does not exist. JavaScript does get to receive these high-level events from HID devices. The browser does not explicitly tell the user that it is receiving them because delivery of the event is entirely under the user control. For example, JavaScript will only receive an event from the user's keyboard if the user has pressed a key while the page is in focus. JavaScript cannot send data to the device, only receive it.
WebUSB is not a JavaScript library but an API that is provided by the web browser.
In contrast to the discussion of HID above browsers implementing WebUSB (of which currently there is only Chrome) do notify the user if a page is connected to a USB device. First, there is a permission prompt that gives the user the choice of whether and which device the page can access. Second, there is an indicator on the tab (similar to the one indicating that the page is playing or recording audio) whenever the page has an active connection.
Therefore a malicious website cannot hit your USB device without your knowledge.
Moving from the world of Embedded Micro controllers and C, to C++ with wxWidgets.
I've created a simple GUI program, using codeblocks and wxWidgets to interface with a USB Hid device I've made using the HIDAPI from signal11.
Using simple buttons, I can connect, disconnect and check firmware software versions on the device.
What I want to be able to do is have the GUI automatically detect if a device is present or not, so If I unplug my device the GUI responds (Greys everything out) or re enables everything when plugged in.
Is this something that needs a never ending thread to achieve, or is there a better way? I would usually do something like this in an interrupt routine on a micro controller, but am unsure of its equivalent on the desktop platform?
USB devices connections/disconnections are not handled by wxWidgets, so you will have to use platform-specific APIs for this and they vary depending on your platform. Under Windows, you actually don't need a background thread because you get these notifications in the form of Windows WM_DEVICECHANGE message, so you can simply override MSWHandleMessage() in the window for which you had previously asked Windows to send these messages to using RegisterDeviceNotification() and handle them there.
I have a browser plugin which doesn't have visual interface and works in the background.The plugin is built using NPAPI technology.The browser plugin is used to Set Up USB device. Now we want to change it and use some other technology,since chrome is planing to move away from NPAPI.
I have gone through Google Native Client(Nacl) and PPAPI, it is good technology and since it is Native Client means it allows the hardware access in my case USB devices.
I wanted to confirm my understanding on this.Please let me know whether Google Native Client supports USB device access from web.
I have to simulate a USB Device for automation and testing purposes (in Linux). Original driver/application for this device uses “libusb” to communicate with it.
I don’t have much experience in Linux and Simulation, after some searching I have understood that I need to write a kernel level driver and an application in user-space to simulate that device. Is this right? If Yes, How can this be done?
Thanks in Advance.
Finally implemented it by modifying "libusb", modified it to send and receive usb transfers from message queue instead of usbfs. Programmed my simulator to create libsub type transfers and send/receive them using message queues as well.
Simulator now interprets the incoming transfers and sends it to a command parser, which sends request/message to automation system using sockets in a specific format. Automation system sends it's instruction by sending to command parser using socket. This socket invokes method specific to each request in simulator, Now simulator forms an appropriate transfer structure and passes to device plugin (via libusb) through message queue.
I think what you're looking for would be called a virtual USB device. Currently there is nothing in standard Kernel.Some virtual machine provides USB emulation.e.g. KVM provides USB emulation. There is framework gadget in which might look for your solution.
Or find something in Linux USB project
Thanks,
Abhijeet
The usb-vhci project could be of use if you want the device to be presented to the kernel in the same way as real hardware.