Repository navigation
feat: attribute hid, usb and serial device permissions to the requesting frame - #53657
Open
MarshallOfSound wants to merge 6 commits into
Open
MarshallOfSound wants to merge 6 commits into
MarshallOfSound wants to merge 6 commits into
Conversation
This was referenced Sep 7, 2026
MarshallOfSound
force-pushed
the
feat/device-permissions-requesting-frame
branch
from
September 7, 2026 15:52
d081f7f to
a62f42b
Compare
MarshallOfSound
force-pushed
the
feat/device-permissions-requesting-frame
branch
2 times, most recently
from
September 10, 2026 03:25
28a6f9a to
5e42fe7
Compare
…rame * setPermissionCheckHandler receives details.frame and details.embeddingOrigin for every frame-scoped check * HasDevicePermission is gated on the hid/usb permission check, so denying the check also hides granted devices from getDevices()/open() * chooser selections are always recorded and reported to setDevicePermissionHandler as details.selected, with details.frame and, for hid, the deviceId the chooser reported; without a handler a selection is a grant as before * forget() notifies content from a posted task so every document of the origin drops the device; the carried patch hands the frame to UsbDelegate::RevokeDevicePermissionWebInitiated and keys SerialService on the requesting frame as well * hid-device-revoked, usb-device-revoked, usb-device-added and usb-device-removed carry the requesting frame * setUSBProtectedClassesHandler receives details.origin and details.frame * UsbChooserContextFactory serves in-memory partitions (WebUSB was a no-op there); UsbChooserController guards against its handler destroying the frame; usb details.device.configurations[].interfaces is a list and configuration sits on the device; persistent grants are de-duplicated * the smart-card auto-grant keyed on Chrome extension IDs is removed
* select-serial-port, serial-port-added and serial-port-removed carry the requesting frame * HasPortPermission is gated on the serial permission check, passes the frame, details.selected and portId to setDevicePermissionHandler and consults it for ports without a persistent id * forget() notifies content so other documents' connections close * forward OnPortConnectedStateChanged so navigator.serial fires connect/disconnect for Bluetooth serial ports * observe every session's SerialChooserContext, not only the first one used * delete SerialChooserController with its frame and guard against its handler destroying the frame
Add in-process fake HID, USB and serial device managers behind
process._linkedBinding('electron_common_testing') and
spec/api-device-permissions-spec.ts, which drives requestDevice/requestPort,
open, getDevices and forget from the main frame, a cross-origin iframe and a
sandboxed iframe and asserts what every handler and event receives, plus
revocation across documents, handler veto, check gating, chooser handlers
destroying the window, usb details shape, protected-classes identity,
serial-port-added / usb-device-added frames and serial connect/disconnect.
…hange Add docs/tutorial/permissions.md covering which frame each permission and device handler is told about, how that differs from Chrome's top-level-site model, and how to key on the top-level site instead; link it from the devices, security and examples pages; add the breaking-changes entry.
MarshallOfSound
force-pushed
the
feat/device-permissions-requesting-frame
branch
from
September 17, 2026 23:26
5e42fe7 to
56cc1b5
Compare
|
Release note looks good now. |
This was referenced Sep 21, 2026
4 of 5 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
Stacked on #53656 (base branch
fix/hid-usb-check-requesting-frame; retarget tomainonce that lands). Main-only for 46: this changes observable behaviour and is recorded indocs/breaking-changes.md.Makes every WebHID / WebUSB / Web Serial decision identify the requesting frame and agree on its origin, and documents the model:
setPermissionCheckHandlergetsdetails.frameanddetails.embeddingOriginon every frame-scoped check;setDevicePermissionHandlergetsdetails.frameanddetails.selected(+deviceId/portIdas the chooser reported them);setUSBProtectedClassesHandlergetsdetails.origin/details.frame;select-serial-port,serial-port-added/removed,usb-device-added/removed,hid-device-revokedandusb-device-revokedcarry the requesting frame.hid/usb/serialcheck gatesgetDevices()/open()as well as the chooser; chooser selections are always recorded and reported tosetDevicePermissionHandler(which is now consulted for every device);forget()closes the device in every document of the origin (chooser contexts notify content; carried patch keysSerialServiceon the requesting frame and hands the frame toUsbDelegate::RevokeDevicePermissionWebInitiated).SerialChooserContextis observed (only the first was, soconnect/disconnect/revocation were dead elsewhere);OnPortConnectedStateChangedforwarded; chooser controller deleted with its frame. USB: in-memory partitions get aUsbChooserContext(WebUSB was a no-op there andrequestDevice()could crash, fixes [Bug]: navigator.usb.requestDevice() crashes the browser process (SIGSEGV) on a named session partition #52383); chooser-handler re-entrancy guard;details.device.configurations[].interfacesis an array; smart-card extension-ID auto-grant removed.spec/api-device-permissions-spec.ts(attribution per topology, chooser identity, handler veto, check gating, cross-document revocation, chooser handler destroying the window, usb details shape, protected classes,*-addedframes, serial connect/disconnect).docs/tutorial/permissions.mddescribing Electron's web permission model, how it differs from Chrome's top-level-site model and how to key onframe.top.originto match Chrome;breaking-changes.mdentry for 46.Checklist
npm testpassesRelease Notes
Notes:
hid,usbandserialpermission handlers and events now identify the requesting frame viadetails.frameor a trailingframeargument.setDevicePermissionHandlernow receivesdetails.selected.hid,usborserialpermission check now blocks access to already-granted devices.forget()now closes the device in every document of the origin.