Skip to content

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

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

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

Conversation

@AutomatedTester
Copy link
Copy Markdown
Member

@AutomatedTester AutomatedTester commented Jun 4, 2026

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
Copy link
Copy Markdown

CLAassistant commented Jun 4, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ AutomatedTester
❌ claude
You have signed the CLA already but the status is still pending? Let us recheck it.

@selenium-ci selenium-ci added C-py Python Bindings B-build Includes scripting, bazel and CI integrations labels Jun 4, 2026
claude and others added 6 commits June 5, 2026 15: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

https://claude.ai/code/session_018zDh8UVeD7rTyJQQZpAVne
Extends bidi_permissions_tests.py with integration tests that drive a real
browser for every new convenience method added in the permissions API.

https://claude.ai/code/session_018zDh8UVeD7rTyJQQZpAVne
Adds PermissionsManager.grant_all(descriptors, *, origin, user_context)
and the matching Permissions.grant_all() wrapper, allowing multiple
permissions to be granted in a single call — closing the gap with
Playwright's grant_permissions(["geo", "camera"]) API.

Each granted permission is tracked individually so reset_all() cleans
them all up. Unit and browser tests included.

https://claude.ai/code/session_018zDh8UVeD7rTyJQQZpAVne
grant() and reset() now each accept a single descriptor, an iterable of
descriptors, or (for reset) no argument to reset all tracked overrides.
This removes the separate grant_all() and reset_all() methods in favour
of a unified API:

    driver.permissions.grant(["geolocation", "camera"], origin=origin)
    driver.permissions.reset()   # clears all tracked overrides

A new _is_single_descriptor() helper distinguishes bare strings and
PermissionDescriptor objects from iterables without misidentifying a
permission name string as a sequence of characters.

Tests updated accordingly.

https://claude.ai/code/session_018zDh8UVeD7rTyJQQZpAVne
- _permissions_handlers.py: change __exit__ return type from bool to
  Literal[False] to satisfy mypy exit-return rule
- Unit tests: remove unused PermissionsManager import (F401), fix import
  ordering (I001)
- Browser tests: add missing docstrings to all new test functions (D103)

https://claude.ai/code/session_018zDh8UVeD7rTyJQQZpAVne
@AutomatedTester AutomatedTester force-pushed the claude/permissions-api-design-MKlID branch from aa9a317 to df04f26 Compare June 5, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants