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
66.05k stars 3.6k forks source link

[BUG] page.route causes requests to timeout #10376

Open monkekode opened 2 years ago

monkekode commented 2 years ago

Context:

System:

Code Snippet

import {chromium} from "playwright";
const b = await chromium.launch({
    headless: false
})
const p = await b.newPage();
await p.route(() => false, async (route) => {
    await route.continue();
});
await p.goto('https://www.google.com');

Describe the bug

Any usage of page.route makes subsequest requests timeout. Even though no routes are matched and all requests are set to continue. If I remove the p.route part, it starts to work.

monkekode commented 2 years ago

Looks like this happens on sites owned by google: google.com, youtube.com, but not on facebook.com, microsoft.com.

aslushnikov commented 2 years ago

I can reproduce.

aslushnikov commented 2 years ago

Regression bisect: https://chromium.googlesource.com/chromium/src/+log/ea0ea27fc53804b2c500fbbef6cc0dea6b8014c5..7c30ae02d6d79c5e2c2ab38d2d880b043d16ec00

aslushnikov commented 2 years ago

Fix is pushed & cherry-picked to 1.17, but maybe we need a better solution later.

yury-s commented 2 years ago

Debugging observations: it is only reproducible in headful and when response interception is on. We receive two Fetch.requestPaused events for the same request and get stuck waiting for request extra info for the second one:

  pw:protocol ◀ RECV {"method":"Fetch.requestPaused","params":{"requestId":"interception-job-1.1","request":{"url":"https://www.google.com/","method":"GET","headers":{"Upgrade-Insecure-Requests":"1","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4744.0 Safari/537.36","Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9","sec-ch-ua":"\"(Not(A:Brand\";v=\"8\", \"Chromium\";v=\"98\"","sec-ch-ua-mobile":"?0","sec-ch-ua-platform":"\"macOS\""},"initialPriority":"VeryHigh","referrerPolicy":"strict-origin-when-cross-origin"},"frameId":"197072FB470F30BEA2C9C66F19E7BF20","resourceType":"Document","networkId":"0D10331B4121BC1248597649CF3FF5AA"},"sessionId":"E9134B4B5CFD25CA8EBB016F9C97E3E7"} +0ms
requestId = 0D10331B4121BC1248597649CF3FF5AA  requestWillBeSentEvent = [object Object]
  pw:protocol SEND ► {"id":25,"method":"Fetch.continueRequest","params":{"requestId":"interception-job-1.1"},"sessionId":"E9134B4B5CFD25CA8EBB016F9C97E3E7"} +2ms
  pw:protocol ◀ RECV {"id":25,"result":{},"sessionId":"E9134B4B5CFD25CA8EBB016F9C97E3E7"} +1ms
  pw:protocol ◀ RECV {"method":"Page.lifecycleEvent","params":{"frameId":"197072FB470F30BEA2C9C66F19E7BF20","loaderId":"C6B7285CC5665B28080042D55A9AB01B","name":"networkAlmostIdle","timestamp":155310.035678},"sessionId":"E9134B4B5CFD25CA8EBB016F9C97E3E7"} +218ms
  pw:protocol ◀ RECV {"method":"Page.lifecycleEvent","params":{"frameId":"197072FB470F30BEA2C9C66F19E7BF20","loaderId":"C6B7285CC5665B28080042D55A9AB01B","name":"networkIdle","timestamp":155310.035678},"sessionId":"E9134B4B5CFD25CA8EBB016F9C97E3E7"} +0ms
  pw:protocol ◀ RECV {"method":"Fetch.requestPaused","params":{"requestId":"interception-job-2.0","request":{"url":"https://www.google.com/","method":"GET","headers":{"Upgrade-Insecure-Requests":"1","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4744.0 Safari/537.36","Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9","sec-ch-ua":"\"(Not(A:Brand\";v=\"8\", \"Chromium\";v=\"98\"","sec-ch-ua-mobile":"?0","sec-ch-ua-platform":"\"macOS\"","sec-ch-ua-full-version":"\"98.0.4744.0\"","sec-ch-ua-arch":"\"x86\"","sec-ch-ua-platform-version":"\"10.15.7\"","sec-ch-ua-model":"\"\""},"initialPriority":"VeryHigh","referrerPolicy":"strict-origin-when-cross-origin"},"frameId":"197072FB470F30BEA2C9C66F19E7BF20","resourceType":"Document","networkId":"0D10331B4121BC1248597649CF3FF5AA"},"sessionId":"E9134B4B5CFD25CA8EBB016F9C97E3E7"} +0ms
requestId = 0D10331B4121BC1248597649CF3FF5AA  requestWillBeSentEvent = undefined
    pw:protocol SEND ► {"id":26,"method":"Target.disposeBrowserContext","params":{"browserContextId":"9EABA17B08111254D09A89F826EEFCCE"}} +2s
  pw:protocol ◀ RECV {"method":"Inspector.detached","params":{"reason":"Render process gone."},"sessionId":"E9134B4B5CFD25CA8EBB016F9C97E3E7"} +3ms

The second pause event comes with a longer list of sec-ch-* headers:

"sec-ch-ua":"\"(Not(A:Brand\";v=\"8\", \"Chromium\";v=\"98\"","sec-ch-ua-mobile":"?0","sec-ch-ua-platform":"\"macOS\""
"sec-ch-ua":"\"(Not(A:Brand\";v=\"8\", \"Chromium\";v=\"98\"","sec-ch-ua-mobile":"?0","sec-ch-ua-platform":"\"macOS\"",  "sec-ch-ua-full-version":"\"98.0.4744.0\"","sec-ch-ua-arch":"\"x86\"","sec-ch-ua-platform-version":"\"10.15.7\"","sec-ch-ua-model":"\"\""
yury-s commented 2 years ago

Filed upstream bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1279953

pavelfeldman commented 2 years ago

It looks like googe.com is only affected because of the brave experiments Chromium team is conducting. Let's see how real those scenarios will be in the real life.

David-Vithayathil commented 2 years ago

The issue is not restricted to google.com

I have written a playwright test script that visits a website and uses page.route to intercept and inject a JS script. The request hangs only for chromium browser and works consistently for firefox.

tuky commented 1 year ago

This is still an issue that we have with python playwright. Any news on this?

mymem0 commented 1 year ago

I have same problem. any update?

sphingu commented 2 months ago

do we have any update on this issue ?