Skip to content

Conversation

@hbenl
Copy link
Collaborator

@hbenl hbenl commented Nov 11, 2025

The current BiDi implementation for context.route() adds the intercepts whenever a new Page is created and has 2 issues:

  • intercepting the first request of a popup is racy since it may start before Playwright had a chance to add the intercept
  • no intercepts are added for Pages that were created before the route

This PR adds intercepts for context.route() at the BrowserContext level and uses the Page level intercepts only for page.route().

Fixes the following tests (some of which were intermittent and/or only failed locally):

  • tests/library/browsercontext-route.spec.ts:
    • "should unroute"
    • "should support the times parameter with route matching"
    • "should work if handler with times parameter was removed from another handler"
    • "should overwrite post body with empty string"
    • "should not chain fulfill"
  • tests/library/popup.spec.ts:
    • "should respect routes from browser context"
  • tests/library/unroute-behavior.spec.ts:
    • "context.unroute should not wait for pending handlers to complete"
    • "context.unrouteAll should wait for pending handlers to complete"
    • "context.unrouteAll should not wait for pending handlers to complete if behavior is ignoreErrors"

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Skn0tt Skn0tt requested a review from yury-s November 12, 2025 16:27

async doUpdateRequestInterception(): Promise<void> {
if (this.requestInterceptors.length > 0 && !this._interceptIdPromise) {
this._interceptIdPromise = this._browser._browserSession.send('network.addIntercept', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to handle multiple concurrent calls of route, you can have a separate field isUpdatingInterception or something. But in the Playwright API the route/unroute methods are async and the contract is that the user awaits the result before making next call. Concurrent calls are a best effort.

Let's await for the command result and save the intercept id into a field (instead of saving a promise and awaiting it only when it's time to disable interception). I don't know what ordering guarantees Bidi provides and wether it is safe to send-and-forget here. I'd avoid relying on that and await for the command response before returning from this method.

@github-actions
Copy link
Contributor

Test results for "MCP"

2432 passed, 116 skipped


Merge workflow run.

@github-actions
Copy link
Contributor

Test results for "tests 1"

5 flaky ⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:1079 › cli codegen › should not throw csp directive violation errors `@firefox-ubuntu-22.04-node18`
⚠️ [firefox-library] › library/inspector/cli-codegen-pick-locator.spec.ts:35 › should update locator highlight `@firefox-ubuntu-22.04-node18`
⚠️ [firefox-page] › page/page-emulate-media.spec.ts:144 › should keep reduced motion and color emulation after reload `@firefox-ubuntu-22.04-node18`
⚠️ [playwright-test] › ui-mode-trace.spec.ts:397 › should work behind reverse proxy `@macos-latest-node18-2`
⚠️ [playwright-test] › ui-mode-test-attachments.spec.ts:61 › should contain binary attachment `@windows-latest-node18-2`

40256 passed, 787 skipped


Merge workflow run.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants