Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpler than a serial number or permanent unique identifier: session-specific device identifier #90

Open
JamesB7 opened this issue Feb 9, 2022 · 5 comments

Comments

@JamesB7
Copy link

JamesB7 commented Feb 9, 2022

If a permanent unique identifier is not on the cards any time soon for WebHID, it would be helpful at least to have a session-specific device identifier, which would be destroyed upon closing the tab.

Reason being, right now, I set a user property to keep track of the same device between getDevices() and requestDevice(). This works, so that I don't try to connect to the same device twice. However, if the user disconnects and reconnects the device, I do have access in getDevices(), but because it has recreated the device, I lose my tracking property.

The end result of this is, if the device drops off and comes back, I can't tell from getDevices() that it's the same device. I need this, because upon uploading settings in my program, I reboot the device so that its interface goes back to its main menu.

This would be very helpful. If long-lasting tabs are a concern, on a disconnected device the identifier could be destroyed after a timeout.

Thanks!

James

@reillyeon
Copy link
Contributor

Unfortunately from an implementation perspective scoping this feature request down to a session-specific device identifier that survives the device being reconnected doesn't make the problem any simpler than creating an identifier that is persistent between sessions. Today, if the device isn't disconnected then getDevices() and requestDevice() will return HIDDevice instances that are === comparable to each other. Difficulty occurs when the device is disconnected and the browser needs to decide that the device that the OS told it got disconnected before is the same as the device the OS told it just connected and give it the same identifier.

@JamesB7
Copy link
Author

JamesB7 commented Feb 23, 2022

For any device with a serial number, this is easily available on all platforms that I know of. Which platform is this challenging on?

In my C# library "HIDSharp" I provide a persistent identifier "DevicePath". Obviously one would not expose the actual value to the web, but for the common platforms anyway:

Windows: the device path
MacOS: the result of IORegistryEntryGetPath called with "IOService"
Linux: the result of udev_list_entry_get_name while enumerating the "hidraw" subsystem

Let me know if there are any details I can provide that would be helpful.

(As an aside, the reason I mention this separate from 'persistent between sessions' is that this case is substantially less of a security concern. But for things like firmware updates it is important.)

@reillyeon
Copy link
Contributor

It's hiding the actual value of "DevicePath" (or a similar property) that is challenging. We already have this data within the browser on all platforms. My point in the previous comment was that making the identifier session scoped is not much easier than making is persistent as most of the same corner cases still apply. This is on our project backlog so I just ask for your patience.

@nondebug, can you close this as a duplicate of #7 (and give me issue management permissions on this repo).

@davisford
Copy link

Unfortunately from an implementation perspective scoping this feature request down to a session-specific device identifier that survives the device being reconnected doesn't make the problem any simpler than creating an identifier that is persistent between sessions.

Would it at least be possible to provide a unique session id per device that does not survive a disconnect event? Anything at this point would be welcome.

@reillyeon
Copy link
Contributor

Would it at least be possible to provide a unique session id per device that does not survive a disconnect event? Anything at this point would be welcome.

This is already possible as HIDDevice instances are === comparable. Every call to getDevices() will return the same instances until disconnection. If you want to give a device a human-readable ID you can generate one and maintain a Map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants