[py] Add high-level BiDi network authentication handler API#17629
Merged
Conversation
BiDi UrlPatternPattern properties match literally and browsers reject wildcard characters in them (chromium-bidi: "Forbidden characters"). Omitted properties match anything, so wildcard-bearing glob components are now dropped from the browser-side filter; Python-side glob matching narrows the results.
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.
🔗 Related Issues
Follows #17619 (request handlers) and #17623 (response handlers); Phase 3 of the BiDi Protocol API Design.
💥 What does this PR do?
Adds the callback-based authentication handler API to
driver.network, aligned with the Authentication Handling section of the cross-binding BiDi API design:AuthenticationRequest(url,realm,scheme,challenges) at theauthRequiredphase and may callprovide_credentials(username, password)orcancel(). Reconciliation issues exactly onenetwork.continueWithAuthper challenge (cancel > provide_credentials > browserdefault), so purely observational handlers never stall the pageadd_authentication_handler(handler)) matches everythingclear_request_handlersnow preserves authentication handlers alongside response handlers (and resubscribes both registries after the event-handler sweep)add_auth_handler(username, password)is unchanged; its docstring cross-references the new API and warns against mixing the two on one challengeThis also fixes a latent wire-level bug the new browser tests exposed:
glob_to_url_patternemitted wildcard characters insideUrlPatternPatternproperties (e.g."pathname": "/*"), which browsers reject withinvalid argument: Forbidden characters— the spec says pattern properties match literally. Wildcard-bearing components are now omitted (omitted properties match anything) and Python-side glob matching narrows the results. Phases 1–2 never hit this in practice because their browser tests only used**/...globs, which skip browser-side filtering entirely.🔧 Implementation Notes
py/private/_network_handlers.py(AuthenticationRequest,AuthHandlerRegistryreusing_BaseHandlerRegistry) with thin glue inpy/private/bidi_enhancements_manifest.pyneeds_fresh_driver: success warms the browser's HTTP auth cache for the origin, which suppressesauthRequiredchallenges in later tests (this also applied to the pre-existing legacytest_continue_with_auth)continueWithAuth, so noxfail_firefoxneeded)🤖 AI assistance
💡 Additional Considerations
network.continueWithAuth,network.addInterceptUrlPattern translation)🔄 Types of changes