r/javascript • • 2h ago

I reverse-engineered my mouse's USB protocol and rebuilt its driver in plain JavaScript with WebHID

https://kanto065.github.io/nacodex-web-driver/

My mouse (NACODEX NJ08 MC) shipped with a 91 MB Windows app. I wanted to see how much of it a web page could replace, and the answer turned out to be all of it.

How it works

Chrome and Edge expose the WebHID API, which lets a page send and receive raw HID reports once the user picks the device. The official app turned out to be an Electron app that uses WebHID too, so I extracted its JavaScript from the installer (without running it), worked out the byte layout for each setting (DPI stages, button mapping, macros, lighting, sleep timer, battery), and rebuilt them in plain JavaScript. There's no framework and no build step, and it runs as a static site.

The weird part

The mouse has no way to report what its LEDs are doing. You can write lighting settings, but you can't read back what they look like. To map the lighting commands, I pointed my laptop webcam at the mouse and recorded every command I sent, then matched each command to the effect in the video.

Things I learned about WebHID

  • It needs a secure context: localhost or HTTPS. Opening the HTML file from disk doesn't work.
  • The user has to pick the device through a browser prompt, so a page can't silently take over your devices.
  • Firefox and Safari don't support it, so it's Chromium-only for now.
  • Settings are written to the mouse's onboard memory, so once they're set the page isn't needed anymore.

Links

It supports 20 NACODEX models in theory, but I've only tested one. Feedback on the code or the protocol handling is welcome.

0 Upvotes

1 comment sorted by

•

u/AutoModerator 2h ago

Project Page (?): https://github.com/kanto065/nacodex-web-driver

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.