[py] Add high-level BiDi permissions API#17631
Conversation
aa9a317 to
df04f26
Compare
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
df04f26 to
b0687ba
Compare
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.
Code Review by Qodo
Context used✅ Compliance rules (platform):
17 rules 1. set_permission breaks positional origin
|
| ''' def set_permission( | ||
| self, | ||
| descriptor: "PermissionDescriptor | str", | ||
| state: "PermissionState | str", | ||
| *, | ||
| origin: str | None = None, | ||
| user_context: str | None = None, | ||
| *, | ||
| embedded_origin: str | None = None, | ||
| ) -> None: | ||
| """Set a browser permission. | ||
|
|
||
| Args: | ||
| descriptor: The permission descriptor or permission name as a string. | ||
| state: The desired permission state (granted, denied, or prompt). | ||
| origin: The origin to scope the permission to. | ||
| user_context: Optional user context ID to scope the permission. | ||
| origin: Keyword-only. The origin to scope the permission to. | ||
| user_context: Keyword-only. Optional user context ID to scope the | ||
| permission. |
There was a problem hiding this comment.
1. set_permission breaks positional origin 📘 Rule violation ≡ Correctness
Permissions.set_permission() now makes origin/user_context (and related scoping args) keyword-only, which breaks existing callers that pass these positionally and will raise TypeError at runtime. This is a backward-incompatible public API change that is being enforced by tests without any prior deprecation period or migration path.
Agent Prompt
## Issue description
`Permissions.set_permission()` was changed so that `origin` and `user_context` (and scoping-related args such as `embedded_origin`) are keyword-only by placing `*` before them. This introduces a runtime backwards-incompatible public API change for any existing callers passing `origin`/`user_context` positionally (now raising `TypeError`) and provides no deprecation period or migration path.
## Issue Context
Tests were updated to assert that positional scoping arguments now raise `TypeError`, confirming the break is intentional and enforced. If the keyword-only style is desired for consistency with other methods (e.g., `grant/deny/reset`), it should be introduced without breaking existing callers (for example, by continuing to accept positional `origin`/`user_context` for now while emitting a deprecation warning and documenting a removal timeline), or by introducing the stricter signature under a new method name/versioned API; if the hard break is truly intended, add explicit migration guidance (release notes/changelog) and ensure all in-repo examples/docs are updated accordingly.
## Fix Focus Areas
- py/private/bidi_enhancements_manifest.py[1918-1934]
- py/test/selenium/webdriver/common/bidi_permissions_tests.py[145-156]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| ''' def override( | ||
| self, | ||
| descriptor: "PermissionDescriptor | str", | ||
| state: "PermissionState | str", | ||
| *, | ||
| origin: str | None = None, | ||
| user_context: str | None = None, | ||
| ): | ||
| """Return a context manager that applies *state* on enter and resets on exit. |
There was a problem hiding this comment.
2. override() missing return type 📘 Rule violation ✧ Quality
The newly added Permissions.override() method signature lacks an explicit return type annotation. This violates the requirement that new function/method signatures include return annotations.
Agent Prompt
## Issue description
The generated `Permissions.override()` method is added without a return type annotation (missing `-> ...`).
## Issue Context
This method returns the context manager created by `self._manager.override(...)`, so it should be annotated (e.g., `-> PermissionOverrideContext`).
## Fix Focus Areas
- py/private/bidi_enhancements_manifest.py[2025-2049]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Introduces a
PermissionsManagerhelper (py/private/_permissions_handlers.py)that layers convenience methods on top of the existing
permissions.setPermissioncommand, following the same handler-module pattern used for network and script.
Changes
_permissions_handlers.pystaged into the bidi package by BazelPermissions.__init__now accepts an optional driver argument (same asScript)bidi_enhancements_manifest.pywires upPermissionsManagerand exposes theconvenience methods on the generated
PermissionsclassBUILD.bazeladds_permissions_handlers.pytocreate-bidi-srcextra_srcsgenerate_bidi.pyextends the driver-arg__init__to the permissions moduleNew API
API comparison: Selenium BiDi vs. Playwright
BrowserContext)driver.permissions)grant_permissions(["geolocation"], origin=…)grant("geolocation", origin=…)grant_permissions(["geo", "camera"], origin=…)grant(["geo", "camera"], origin=…)deny("geolocation", origin=…)clear_permissions()reset("geolocation", origin=…)reset(["geolocation", "camera"], origin=…)clear_permissions()reset()— clears tracked overridesoverride("geolocation", "granted", origin=…)origin=origin=user_context=set_permission(descriptor, state, origin)https://claude.ai/code/session_018zDh8UVeD7rTyJQQZpAVne