Skip to content

[py] fix add_request_handler ignoring url_patterns on callback= path#17666

Open
titusfortner wants to merge 1 commit into
trunkfrom
url_pattern_py
Open

[py] fix add_request_handler ignoring url_patterns on callback= path#17666
titusfortner wants to merge 1 commit into
trunkfrom
url_pattern_py

Conversation

@titusfortner

Copy link
Copy Markdown
Member

🔗 Related Issues

💥 What does this PR do?

Fixes the high-level driver.network.add_request_handler(callback=...) form so it honors url_patterns. Previously, passing the handler as a keyword left event=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 to url_patterns.

🤖 AI assistance

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s): Claude Code (Opus 4.8)
    • What was generated: the fix and its regression test
    • I reviewed all AI output and can explain the change

🔄 Types of changes

  • Bug fix (backwards compatible)

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>
@qodo-code-review

qodo-code-review Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Qodo Logo

@selenium-ci selenium-ci added the C-py Python Bindings label Jun 10, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Fix BiDi Network.add_request_handler callback= path to honor url_patterns
🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

Walkthroughs

Description
• 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.
Diagram
graph 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"]
Loading
High-Level Assessment

The 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.

Grey Divider

File Changes

Bug fix (1)
bidi_enhancements_manifest.py Fallback to url_patterns when callback= is used without an event +2/-1

Fallback to url_patterns when callback= is used without an event

• Fixes the callable(callback) dispatch branch so that when event is None (common with callback= keyword usage), the handler registration uses url_patterns instead of passing None. This prevents accidentally creating a global intercept that matches every request.

py/private/bidi_enhancements_manifest.py


Tests (1)
bidi_network_tests.py Add regression test for callback= + url_patterns scoping +13/-0

Add regression test for callback= + url_patterns scoping

• Adds a unit test asserting that network.add_request_handler(callback=..., url_patterns=...) results in network.addIntercept receiving the translated/scoped urlPatterns rather than an unscoped intercept.

py/test/unit/selenium/webdriver/common/bidi_network_tests.py


Grey Divider

Qodo Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-py Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants