Skip to content

[py] Add high-level BiDi permissions API#17631

Open
AutomatedTester wants to merge 2 commits into
trunkfrom
claude/permissions-api-design-MKlID
Open

[py] Add high-level BiDi permissions API#17631
AutomatedTester wants to merge 2 commits into
trunkfrom
claude/permissions-api-design-MKlID

Conversation

@AutomatedTester

@AutomatedTester AutomatedTester commented Jun 4, 2026

Copy link
Copy Markdown
Member

Introduces a PermissionsManager helper (py/private/_permissions_handlers.py)
that layers convenience methods on top of the existing permissions.setPermission
command, following the same handler-module pattern used for network and script.

Changes

  • New _permissions_handlers.py staged into the bidi package by Bazel
  • Permissions.__init__ now accepts an optional driver argument (same as Script)
  • bidi_enhancements_manifest.py wires up PermissionsManager and exposes the
    convenience methods on the generated Permissions class
  • BUILD.bazel adds _permissions_handlers.py to create-bidi-src extra_srcs
  • generate_bidi.py extends the driver-arg __init__ to the permissions module
  • Unit tests and browser tests for all new methods

New API

# Grant one or more permissions
driver.permissions.grant("geolocation", origin=origin)
driver.permissions.grant(["geolocation", "camera"], origin=origin)

# Deny a permission
driver.permissions.deny("geolocation", origin=origin)

# Reset one, several, or all tracked overrides
driver.permissions.reset("geolocation", origin=origin)
driver.permissions.reset(["geolocation", "camera"], origin=origin)
driver.permissions.reset()  # clears all overrides applied via grant/deny/override

# Temporary override — resets to prompt on exit, even if an exception is raised
with driver.permissions.override("geolocation", "granted", origin=origin):
    ...

API comparison: Selenium BiDi vs. Playwright

Feature Playwright (BrowserContext) Selenium BiDi (driver.permissions)
Grant one grant_permissions(["geolocation"], origin=…) grant("geolocation", origin=…)
Grant many grant_permissions(["geo", "camera"], origin=…) grant(["geo", "camera"], origin=…)
Deny ❌ not supported — denied is the browser default deny("geolocation", origin=…)
Reset one ❌ only bulk via clear_permissions() reset("geolocation", origin=…)
Reset many ❌ only bulk reset(["geolocation", "camera"], origin=…)
Reset all clear_permissions() reset() — clears tracked overrides
Temporary override ❌ no context manager override("geolocation", "granted", origin=…)
Origin scoping ✅ optional origin= ✅ optional origin=
User context scoping ❌ not supported user_context=
Low-level access ❌ no direct BiDi access set_permission(descriptor, state, origin)

https://claude.ai/code/session_018zDh8UVeD7rTyJQQZpAVne

@CLAassistant

CLAassistant commented Jun 4, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@selenium-ci selenium-ci added C-py Python Bindings B-build Includes scripting, bazel and CI integrations labels Jun 4, 2026
@AutomatedTester AutomatedTester force-pushed the claude/permissions-api-design-MKlID branch from aa9a317 to df04f26 Compare June 5, 2026 14:28
Introduces a PermissionsManager helper (py/private/_permissions_handlers.py)
that layers grant/deny/reset/reset_all and a context manager (override) on top
of the existing permissions.setPermission command, following the same
handler-module pattern used for network and script.

Changes:
- New _permissions_handlers.py staged into the bidi package by Bazel
- Permissions.__init__ now accepts an optional driver argument (same as Script)
- bidi_enhancements_manifest.py wires up PermissionsManager and exposes the
  convenience methods on the generated Permissions class
- BUILD.bazel adds _permissions_handlers.py to create-bidi-src extra_srcs
- generate_bidi.py extends the driver-arg __init__ to the permissions module
- New unit tests cover grant/deny/reset/reset_all and the context manager
@AutomatedTester AutomatedTester force-pushed the claude/permissions-api-design-MKlID branch from df04f26 to b0687ba Compare June 8, 2026 14:08
@AutomatedTester AutomatedTester added the A-needs decision TLC needs to discuss and agree label Jun 11, 2026
Aligns the low-level set_permission command with the grant/deny/reset/
override convenience methods, where origin and user_context are already
keyword-only. Internal callers and tests updated accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-needs decision TLC needs to discuss and agree B-build Includes scripting, bazel and CI integrations C-py Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants