[py] fix add_request_handler ignoring url_patterns on callback= path#17666
Open
titusfortner wants to merge 1 commit into
Open
[py] fix add_request_handler ignoring url_patterns on callback= path#17666titusfortner wants to merge 1 commit into
titusfortner wants to merge 1 commit into
Conversation
When the handler is passed via callback=, event is None so the high-level dispatch branch called add_handler(event, callback) with event=None, dropping url_patterns and intercepting every request instead of only the requested patterns. Fall back to url_patterns when event is None so all keyword calling forms scope the intercept consistently. Adds a unit regression test asserting the callback=/url_patterns= form sends the scoped urlPatterns to network.addIntercept. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Contributor
PR Summary by QodoFix BiDi Network.add_request_handler callback= path to honor url_patterns WalkthroughsDescription• Ensure callback= request handlers fall back to url_patterns when event is omitted. • Prevent unscoped intercepts that previously matched every request. • Add regression test asserting urlPatterns are sent to network.addIntercept. Diagramgraph TD
A["Caller code"] --> B["Network.add_request_handler"] --> C["Dispatch: patterns = event ?? url_patterns"] --> D["RequestHandlers.add_handler"] --> E["BiDi: network.addIntercept"] --> F["Browser"]
High-Level AssessmentThe chosen fix is the simplest and most consistent approach: it makes the callback= (keyword) dispatch path behave like the positional path by ensuring patterns are derived from url_patterns when event is None. Considered alternatives (e.g., signature/overload restructuring) would be more invasive for minimal additional value. File ChangesBug fix (1)
Tests (1)
|
3 tasks
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
💥 What does this PR do?
Fixes the high-level
driver.network.add_request_handler(callback=...)form so it honorsurl_patterns. Previously, passing the handler as a keyword leftevent=None, which dropped the patterns and intercepted every request instead of only the ones the caller scoped.🔧 Implementation Notes
The keyword (
callback=) and positional dispatch paths are now consistent — when no positional event is given, the intercept falls back tourl_patterns.🤖 AI assistance
🔄 Types of changes