Can I access an USB HID in Chrome without an App?
Asked Answered
B

1

5

I want to use an USB HID from a website. The website will only be accessed by Chrome browsers. The solution should require a minimum amount of extra software and setup for the website user to work.

The USB device presents itself as USB HID to the OS and I need to write and read byte arrays to and from it in order to implement the manufacturers specification for some of the device's features.

My current solution consists of two parts:

  1. A Chrome App that uses the chrome.hid API to talk to the device. This App exposes a Chrome Cross-Extension messaging port to provide and interface for "service calls".
  2. JavaScript code on the website that sends requests to the Chrome App, which then talks to the USB device to process the request.

In order to make it easier for the user I want to get rid of the App, so the user can just surf to the website, grant access to the device if necessary and then be able to use the device. To be clear, I want the user to be able to use the website without installing any dependency first.

I already tried using the WebUSB navigator.usb API but Chrome blocks access to USB HID devices. Is there another way to accomplish this?

Bunche answered 11/4, 2020 at 23:45 Comment(3)
Extensions don't have such an API so the only way is to write a separate utility (e.g. in node.js or python etc.), ask the users to install it, then your extension can communicate with it via nativeMessaging.Scriptorium
I considered that route, but it also involves the user installing that separate utility. I want to get rid of the App because it is an extra dependency to install, before being able to use the website. I will clarify this in the question.Bunche
Question on your question. With your current setup (Chrome App + website) are you able to send and receive data from your HID device without having the browser focused (e.g. is minimized) while doing some other stuff on the same computer, thus data being independently sent and received?Enthral
M
6

WebHID is being developed for this use case. It has been available behind a feature flag since Chrome 78, with an original trial expected in Chrome 84 (probably later due to current Covid-19 situation), estimated stable August 2020 .

For more details: https://github.com/robatwilliams/awesome-webhid

Morehouse answered 13/4, 2020 at 10:47 Comment(1)
Thanks, this is really helpful (especially the resource collection). While having to enable a feature flag is not ideal, I find it much better than installing an App.Bunche

© 2022 - 2024 — McMap. All rights reserved.