Skip to content

feat: attribute Web Bluetooth requests to the requesting frame - #53661

Open
MarshallOfSound wants to merge 4 commits into
feat/device-permissions-requesting-framefrom
feat/bluetooth-permissions-requesting-frame
Open

feat: attribute Web Bluetooth requests to the requesting frame#53661
MarshallOfSound wants to merge 4 commits into
feat/device-permissions-requesting-framefrom
feat/bluetooth-permissions-requesting-frame

Conversation

@MarshallOfSound

Copy link
Copy Markdown
Member

Stacked on #53657. Brings Web Bluetooth in line with the hid/usb/serial model from that PR. Refs #31869, #52383, #53659.

  • session.setPermissionCheckHandler is consulted with a new bluetooth permission for the requesting frame on every Web Bluetooth call; returning false makes Web Bluetooth unavailable to that frame.
  • New session events select-bluetooth-device (details: { deviceList, frame }, callback) and bluetooth-device-added (details: { device, frame }), shaped like the hid/usb chooser events. The webContents select-bluetooth-device event keeps working, gains a trailing frame argument, and is deprecated.
  • If listeners exist but none calls event.preventDefault(), the request is cancelled when discovery finishes instead of Electron selecting the first discovered device. With no listener at all the request is still cancelled immediately.
  • The chooser runs content's event handler from a posted task, so a listener that answers synchronously on the first emission can't re-enter content mid-discovery; the webContents wrapper is looked up per emission rather than cached.
  • DCHECK that kWebBluetoothNewPermissionsBackend stays disabled until ElectronBluetoothDelegate's device-permission methods are implemented.
  • Testing: a bluetooth::FakeCentral driven from the testing binding; spec/api-device-permissions-spec.ts covers attribution per topology, the session events, synchronous answers, unhandled choosers and the check handler.
  • Docs: session + webContents events, check-handler list, devices/permissions tutorials, fiddle, breaking-changes entries.

Notes: Added bluetooth to session.setPermissionCheckHandler and select-bluetooth-device / bluetooth-device-added events on session that identify the requesting frame; the webContents select-bluetooth-device event is deprecated and no longer auto-selects a device when unhandled.

@MarshallOfSound
MarshallOfSound requested review from a team as code owners September 7, 2026 08:28
@MarshallOfSound MarshallOfSound added semver/minor backwards-compatible functionality no-backport labels Sep 7, 2026
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Sep 7, 2026
@MarshallOfSound MarshallOfSound added the backport-check-skip Skip trop's backport validity checking label Sep 7, 2026
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Sep 7, 2026
@MarshallOfSound
MarshallOfSound force-pushed the feat/bluetooth-permissions-requesting-frame branch from 921fdeb to cb8bf18 Compare September 7, 2026 09:03
@MarshallOfSound
MarshallOfSound force-pushed the feat/bluetooth-permissions-requesting-frame branch from 2b63662 to 3555757 Compare September 7, 2026 15:53
@MarshallOfSound MarshallOfSound self-assigned this Sep 7, 2026
MarshallOfSound and others added 4 commits September 7, 2026 19:44
* add a `bluetooth` permission type; ElectronBluetoothDelegate::MayUseBluetooth
  asks session.setPermissionCheckHandler for the requesting frame, so apps
  can turn Web Bluetooth off per origin or frame like hid/usb/serial
* new session events `select-bluetooth-device` (details { deviceList, frame },
  callback) and `bluetooth-device-added` (details { device, frame }); the
  webContents `select-bluetooth-device` event keeps working, gains a trailing
  `frame` argument and is deprecated
* if listeners exist but none calls event.preventDefault(), cancel the
  request once discovery finishes instead of selecting the first discovered
  device; with no listener at all the request is still cancelled immediately
* run the content event handler from a posted task so a listener that answers
  synchronously cannot re-enter content mid-discovery; look the webContents
  wrapper up per emission instead of caching it; only re-emit when a device's
  name actually changes
* DCHECK that kWebBluetoothNewPermissionsBackend stays disabled until the
  delegate's device-permission methods are implemented
* testing: drive a bluetooth::FakeCentral from the testing binding and cover
  attribution per topology, session events, synchronous answers,
  unanswered/unhandled choosers and the check handler in
  spec/api-device-permissions-spec.ts
* docs: session and web-contents events, check-handler list, devices and
  permissions tutorials, fiddle, breaking-changes entries
@MarshallOfSound
MarshallOfSound force-pushed the feat/bluetooth-permissions-requesting-frame branch from 3555757 to c9a2d90 Compare September 7, 2026 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-check-skip Skip trop's backport validity checking no-backport semver/minor backwards-compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant