How to use WebHid form Anvil

I’m trying to use Anvil to build a simple test interface to a custom USB device which is available from the HID interface, I have a simple html/css app that works and can find the device but when I add the code to anvil I get a message:

VM1034 debug:29 [Violation] Permissions policy violation: hid is not allowed in this document.

I assume I need to add something to get permission but the simple test app uses same code and just pops up a user confirmation dialog in the browser which is fine.

Any ideas?

david

How were you serving the html document beforehand?

Local file, guess that has implied permission associated with it, I’m not a JavaScript person!

You could try this in the html head:

<meta http-equiv="Permissions-Policy" content="hid=(self)">

This is untested and just what seemed most feasible from chatgpt.

think your cut and paste went wrong!

turns out it works fine outside of the IDE environment, works in chrome, edge, brave but not firefox

That’s because the HID API isn’t supported by Firefox:

Yup, now wondering how to get this to work within the Anvil IDE, much harder to debug interactions between “python layer” and java script outside of the IDE!

My seeed Studio Xiao is showing up just fine so making progress

Maybe try throwing that meta tag in Native libraries too?

When you run in the IDE your app runs in an iframe, which messes up some permissions. For example, you can’t use Javascript to copy text to the clipboard in that context but it works fine outside the IDE.

If you run in the IDE but run it in a new tab, you break out of the iframe context and generally the permissions are the same as if you were running the app directly, so maybe try that and see if the WebHid parts work that way.

3 Likes

slow response by me but yes, that’s what I found, it would be good to find a way around this as it makes it less attractive as an IDE!

in other news have now got messages arriving from hid device and will update as I go

1 Like

thanks for the help here, I now have a Seeed Xiao sampling temperatures on multiple thermocouples and sending results to an Anvil app running on Chrome on a Windows PC, very cool.

the app looks terrible because I now hand it off to someone competent to design a UI!