#54608: fix: crash on navigator.usb.requestDevice() in in-memory sessions
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
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
- tests are changed or added
- PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, past tense, and no longer than 80 characters.
Release Notes
Notes: Fixed a crash on navigator.usb.requestDevice() in in-memory sessions.
Backports
Semver Impact
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