microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.63k stars 3.57k forks source link

[Bug]: Page.route does not intercept web worker requests #32355

Open iustinpericica opened 2 weeks ago

iustinpericica commented 2 weeks ago

Version

1.43.1

Steps to reproduce

  1. Have a web application with few web workers that performs http requests
  2. Add await page.route("**/*", route => { console.log("Intercepted:", route.request().url()); return route.continue(); }); at the beggining of the test
  3. Http requests initiated by web workers are not catched

Or see the repro repo I created - https://github.com/iustinpericica/repro_pw_web_workers

Expected behavior

I would expect to see those web worker requests.

Actual behavior

I can not see web worker requests.

Additional context

No response

Environment

Windows, Browser Tests
iustinpericica commented 2 weeks ago

Repro: https://github.com/iustinpericica/repro_pw_web_workers

Skn0tt commented 2 weeks ago

Thanks for the repro! This is interesting. It seems to work fine for Webkit and Firefox, but not for Chromium:

❯ npx playwright test

Running 3 tests using 3 workers
[chromium] › example.spec.ts:3:5 › has title
Intercepted: http://localhost:3000/browser-sync/socket.io/?EIO=4&transport=polling&t=P6TgL9K&sid=ZmkUOqVAdPgLLx8bAAAC
Intercepted: http://localhost:3000/browser-sync/socket.io/?EIO=4&transport=polling&t=P6TgL9N&sid=ZmkUOqVAdPgLLx8bAAAC
Intercepted: https://jsonplaceholder.typicode.com/posts/1
[webkit] › example.spec.ts:3:5 › has title
Intercepted: http://localhost:3000/browser-sync/socket.io/?EIO=4&transport=polling&t=P6TgLGo&sid=pFuMyW7mZ9rfbhbRAAAE
Intercepted: http://localhost:3000/browser-sync/socket.io/?EIO=4&transport=polling&t=P6TgLGq&sid=pFuMyW7mZ9rfbhbRAAAE
Intercepted: https://jsonplaceholder.typicode.com/posts/1
Intercepted: https://jsonplaceholder.typicode.com/todos/1
Intercepted: https://jsonplaceholder.typicode.com/todos/1
[firefox] › example.spec.ts:3:5 › has title
Intercepted: http://localhost:3000/browser-sync/socket.io/?EIO=4&transport=polling&t=P6TgLhL&sid=AGDaVChmvMU86TeiAAAG
Intercepted: http://localhost:3000/browser-sync/socket.io/?EIO=4&transport=polling&t=P6TgLhL.0&sid=AGDaVChmvMU86TeiAAAG
Intercepted: https://jsonplaceholder.typicode.com/posts/1
Intercepted: https://jsonplaceholder.typicode.com/todos/1
Intercepted: https://jsonplaceholder.typicode.com/todos/1
  3 passed (4.0s)

This looks very similar to https://github.com/microsoft/playwright/issues/4487. @yury-s could you take a look?

yury-s commented 1 week ago

There is a bug in Chromium, when interception is enabled after the worker has been created, the worker requests are not properly intercepted. As a workaround you can call page.route earlier.

yury-s commented 1 week ago

Filed upstream issue https://issues.chromium.org/u/1/issues/364987731