You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: page.screenshot can hang and timeout option doesn't make it timed out #36702
changed the title [-][Bug]: page.screenshot can hang and `timeout` option doesn't make it timed oout[/-][+][Bug]: page.screenshot can hang and `timeout` option doesn't make it timed out[/+]on Jul 17, 2025
From what I can tell, this behaviour has been in place since at least 1.48. I agree we should throw an error here instead of silently timing out, if possible.
I can make the error appear on every iteration by lowering the setTimeout to 10ms on my machine. Also, if I insert a 100ms wait after the "Start infinite loop" click, then we're throwing the error correctly. So it looks like the problem is that the event loop gets blocked somewhere in the middle of Playwright taking a snapshot, and we don't race the timeout properly in that place. Like in #19374.
I'll take a look at what we can do, but this is also a pretty trivial example. Fumiaki MATSUSHIMA (@mtsmfm) could you elaborate on the real-world page you're experiencing this with? Why is it blocking the event loop, and why is it a problem for you that page.snapshot hangs?
browserTest('should not hang when event loop is blocked',{annotation: {type: 'issue',description: 'https://github.com/microsoft/playwright/issues/36702'}},async({ page })=>{browserTest.setTimeout(1000);awaitpage.evaluate(()=>{setTimeout(()=>{while(true){}},10);});awaitexpect(page.screenshot({timeout: 100})).rejects.toThrow(/page.screenshot:Timeout100msexceeded/);});
We're correctly triggering the timeout, but before we can throw the error we try cleaning up:
I'll take a look at what we can do, but this is also a pretty trivial example. @mtsmfm could you elaborate on the real-world page you're experiencing this with? Why is it blocking the event loop, and why is it a problem for you that page.snapshot hangs?
I can't provide the actual URL as it's not a public website and not owned/maintained by us. But it seems the test target website hangs occasionally. I couldn't find any reliable way to reproduce the hang but I guess if a website doesn't respond (e.g. Aw, Snap! etc) it occurs.
Activity
[-][Bug]: page.screenshot can hang and `timeout` option doesn't make it timed oout[/-][+][Bug]: page.screenshot can hang and `timeout` option doesn't make it timed out[/+]Skn0tt commentedon Jul 17, 2025
From what I can tell, this behaviour has been in place since at least 1.48. I agree we should throw an error here instead of silently timing out, if possible.
I can make the error appear on every iteration by lowering the setTimeout to 10ms on my machine. Also, if I insert a 100ms wait after the "Start infinite loop" click, then we're throwing the error correctly. So it looks like the problem is that the event loop gets blocked somewhere in the middle of Playwright taking a snapshot, and we don't race the timeout properly in that place. Like in #19374.
I'll take a look at what we can do, but this is also a pretty trivial example. Fumiaki MATSUSHIMA (@mtsmfm) could you elaborate on the real-world page you're experiencing this with? Why is it blocking the event loop, and why is it a problem for you that
page.snapshothangs?Skn0tt commentedon Jul 17, 2025
Here's a minimal reproduction test:
We're correctly triggering the timeout, but before we can throw the error we try cleaning up:
playwright/packages/playwright-core/src/server/screenshotter.ts
Line 257 in 6a21e54
That cleanup call is blocked by the event loop. I'm not sure what we can do here, will discuss with Dima.
mxschmitt commentedon Jul 23, 2025
Relates #13253
mtsmfm commentedon Jul 23, 2025
Simon Knott (@Skn0tt)
I can't provide the actual URL as it's not a public website and not owned/maintained by us. But it seems the test target website hangs occasionally. I couldn't find any reliable way to reproduce the hang but I guess if a website doesn't respond (e.g. Aw, Snap! etc) it occurs.
DirkRichter commentedon Aug 20, 2025
We had similar problems when taking large fullscreen screenshots.
Reason is a chomium bug: https://issues.chromium.org/issues/41347676
Solution for us: disable fullPage screenshots