[py] Align driver.network handlers with ADR 17685 - #18051
Open
AutomatedTester wants to merge 1 commit into
Open
AutomatedTester wants to merge 1 commit into
AutomatedTester wants to merge 1 commit into
Conversation
1 of 5 tasks
AutomatedTester
force-pushed
the
copse/look-at-18019-and-create-a-plan-on-what-we-7b5007
branch
from
September 28, 2026 09:14
13cc000 to
1c500a6
Compare
Implements the network handler behavior ADR for the Python bindings, covering the request, response and authentication handler families. - add/remove/clear for each family; add returns a HandlerHandle - URL patterns are validated locally and evaluated by the browser; Selenium no longer expands globs or matches URLs itself - handlers are consulted last-registered first, and the first one to settle a disposition resolves the event and stops the chain - an uncaught handler exception fails the event and is re-raised from the next call into driver.network - opt-in request body collection, with Selenium owning the collector's lifecycle and size cap - handlers are scoped to a window handle or a user context, never both add_auth_handler, remove_auth_handler and the phase-based add_request_handler(event, callback) form still work and now warn. No public method was removed, and every new argument is keyword-only, so existing calls are unaffected.
AutomatedTester
force-pushed
the
copse/look-at-18019-and-create-a-plan-on-what-we-7b5007
branch
from
September 28, 2026 14:02
1c500a6 to
b57eb6e
Compare
This branch has not been deployed
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
Part of #18019 — this is the Python row only.
Implements ADR 17685 — network handler behavior (Accepted) for Python.
💥 What does this PR do?
Brings
driver.networkin line with the eleven decisions in the ADR, across all three handler families (request, response, authentication).add/remove/clearfor each family.addreturns aHandlerHandle. Addsadd_authentication(username, password).fail/respond/submit; settling twice within one handler raisesAlreadySettledError.driver.network.request.original/response.originalexpose the event as it arrived, read-only.collect_body=Trueat registration; Selenium owns the collector's lifecycle and size cap.window_handleor auser_context, never both; passing both raises.Previously handlers were FIFO with priority-based reconciliation, and the response family had no
fail.🔧 Implementation Notes
Backwards compatibility. The ADR's Consequences say the change "is not backwards compatible", but
AGENTS.mdandCONTRIBUTING.mdrequire deprecate-then-remove, so I kept the old surfaces working:add_auth_handler/remove_auth_handlerstill work and now emitDeprecationWarningpointing atadd_authentication.add_request_handler("before_request", cb)form still works and warns.*, so positional order is unchanged on all threeadd_*methods.HandlerHandlesubclassesstr, so decision 1's "handle object" stays usable everywhere the plain string IDs were.Network(conn, driver=None)keeps the newdriverargument optional.I verified this by diffing the generated public surface against trunk rather than by inspection.
The one genuine break is decision 2: a caller passing a glob like
"**/api/**"previously got client-side matching. Rather than fail obscurely at the browser,_url_pattern_from_stringdetects*/?and logs a warning explaining that finer matching now belongs inside the handler. This is the item I'd most like a second opinion on — a warning-only migration for a behavior change is a judgment call, and the TLC may prefer a full deprecation cycle.Two bugs the browser tests caught, both fixed here:
driver.network. Recording the handler's exception after failing raced that very call, so decision 7's "surfaces to the user" was non-deterministic. Now recorded before failing. The regression test fails if the two lines are swapped back — I checked.network.getDatafor a body that will never exist never answers at all — it does not error, it hangs, so the request stays blocked until the command times out. Anycollect_body=Truehandler seeing a GET hit this. Now guarded onbodySize.On (2), the unit fixture had been hiding the problem: it modelled a GET with no
bodySizewhile asserting body collection succeeded.make_before_request_eventnow takesmethodandbody_size. Confirmed against a real browser that a POST body reads correctly inside a blocked handler.🤖 AI assistance
py/private/_network_handlers.py, the generator manifest entries inpy/private/bidi_enhancements_manifest.py, and the unit and browser tests. Design decisions come from ADR 17685; the two bugs above were found by running the browser suites and diagnosed by probing a real browser rather than by assumption.💡 Additional Considerations
Needs a decision before merge:
network.addIntercept, which cannot scope to a user context. This PR intercepts everything and continues out-of-scope events untouched. Worth confirming that is the intended reading.Follow-up work, not in this PR:
🔄 Types of changes
Testing
//py:test/unit/selenium/webdriver/common/bidi_network_tests-unit//py:unitnetwork_tests-chrome-bidinetwork_tests-firefox-bidiruff check/ruff format --checkThe Chrome skip and both Firefox xfails are pre-existing, documented browser limitations, not introduced here. Note that
py/test/selenium/webdriver/common/bidi/network_tests.pysits under the**/bidi/**path thatscripts/format.shexcludes from ruff, so I linted and formatted it explicitly.Co-Authored-By: Copse noreply@copse.dev
Copse-Models: acp:claude-agent-acp#opus[1m]