Skip to content

fix: re-open HID device before write if connection was lost#397

Closed
JoshuadeJong wants to merge 1 commit into
the-via:mainfrom
JoshuadeJong:fix/hid-device-reopen-on-write
Closed

fix: re-open HID device before write if connection was lost#397
JoshuadeJong wants to merge 1 commit into
the-via:mainfrom
JoshuadeJong:fix/hid-device-reopen-on-write

Conversation

@JoshuadeJong
Copy link
Copy Markdown

@JoshuadeJong JoshuadeJong commented May 2, 2026

Problem

On Linux + Chrome, the WebHID device handle can become stale after USB suspend/resume or transient disconnects. The write() method only awaited the initial openPromise, which was already resolved from the first successful open. Subsequent sendReport() calls on the closed handle threw InvalidStateError: The device must be opened first.

Fix

Check _device.opened before each write and re-open if needed.

Testing

  • Verified TypeScript compiles with no errors
  • Tested with BUBBLE 75 (VID: 0x4242, PID: 0x5A4C) on Linux + Chrome

On Linux + Chrome, the WebHID device handle can become stale after
USB suspend/resume or transient disconnects. The write() method only
awaited the initial openPromise, which was already resolved from the
first successful open. Subsequent sendReport() calls on the closed
handle threw InvalidStateError: The device must be opened first.

Check _device.opened before each write and re-open if needed.

Error: InvalidStateError: The device must be opened first
Trace: HID.write (node-hid.ts) -> KeyboardAPI._hidCommand -> KeyboardAPI.flushQueue
Cipulot added a commit that referenced this pull request May 15, 2026
@Cipulot
Copy link
Copy Markdown
Contributor

Cipulot commented May 15, 2026

Addressed in 7c806c5
Added it manually since build fails because of new commit fixing things

@Cipulot Cipulot closed this May 15, 2026
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

Successfully merging this pull request may close these issues.

2 participants