codebytere

#54608: fix: crash on navigator.usb.requestDevice() in in-memory sessions

Merged
Created: Sep 30, 2026, 3:03:12 PM
Merged: Oct 1, 2026, 2:42:12 AM
3 comments
Target: main

Description of Change

Fixes #52383.

Calling navigator.usb.requestDevice() in an in-memory session (a partition without the persist: prefix) crashed the main process. In-memory sessions are off the record, and UsbChooserContextFactory used the default for that case, which is to create no UsbChooserContext at all, so the chooser dereferenced null.

In-memory sessions now get their own UsbChooserContext, as they already do for WebHID and Web Serial. Apart from the crash, WebUSB could not be used in these sessions at all: getDevices() always resolved with an empty list, even when the device permission handler allowed the device, and the page never got connect or disconnect. All of it, including forget() and the session's usb-device-added, usb-device-removed and usb-device-revoked events, now works as in a persistent session. Access is still decided per session by the same handlers.

The existing in-memory spec queried the default session's window by mistake. It now uses the in-memory window and covers requestDevice(); without the fix it takes the test runner down with SIGSEGV. Tested on Linux with no USB device attached, so the paths that need a device are untested.

#53657 has the same fix inside a larger feature. This takes it out on its own so that it can be backported.

Checklist

Release Notes

Notes: Fixed a crash on navigator.usb.requestDevice() in in-memory sessions.

Backports

44-x-y
In-flight
PR Number
#54616
Waiting to be merged
45-x-y
In-flight
PR Number
#54615
Waiting to be merged

Semver Impact

Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.

Semantic Versioning helps users understand the impact of updates:

  • Major (X.y.z): Breaking changes that may require code modifications
  • Minor (x.Y.z): New features that maintain backward compatibility
  • Patch (x.y.Z): Bug fixes that don't change the API
  • None: Changes that don't affect using facing parts of Electron