[py] Add high-level BiDi permissions API#17631
Open
AutomatedTester wants to merge 6 commits into
Open
Conversation
|
|
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
aa9a317 to
df04f26
Compare
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.
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