playwright: [BUG] Page.screenshot method hangs indefinitely

System info

  • Playwright Version: v1.40.0
  • Operating System: All
  • Browser: Chromium
  • Other info: 32GB RAM

Source code

from playwright.sync_api import sync_playwright

print("Starting...")

with sync_playwright() as p:
    try:
        browser = p.chromium.launch(headless=False)
        page = browser.new_page()
        for index in range(10000):
            print("Iteration:", index)
            page.goto('https://google.com')


    except Exception as error:
        if page:
            print("Error: ", {error})
            page.screenshot(path='error.png', timeout=0)
            print("Took a screenshot")

  • I provided exact source code that allows reproducing the issue locally.

Link to the GitHub repository with the repro

Test file (self-contained)

Steps

  • Run the code
  • Wait until the for loop crashes at about 2000-3000 iterations

Expected

The for loop runs all the way through and not crash. The page.screenshot runs normally.

Actual At the 2652 iteration, a Timeout exception gets caught. Chrome gets an Out of Memory error. The code hangs at the page.screenshot line and never completes.

Screenshot

image

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 19 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Was getting this too (and only on some pages, while on others worked)… Setting the env variable PW_TEST_SCREENSHOT_NO_FONTS_READY to 1 seems to have fixed the problem for me.

Found out about it by inspecting the screenshotter code at: https://github.com/microsoft/playwright/blob/c3d8b22198244a692eb059db47c7d80bc9eefed5/packages/playwright-core/src/server/screenshotter.ts#L267

I use 1.48 but still got this error

It would be really amazing to have a list of these env variables as they’re pretty amazing but you only find them if you dig through the source code.

I can also confirm is solves my problems.

I am also experiencing this “waiting for fonts to load” bug in headed mode that leads to a hanging page.screenshot command, but can confirm that in headless mode everything works fine. However in some cases I need to be in headed mode – is there any way to fix this bug?

Hi. I’m facing similar issue - sometimes my tests are getting stuck when i’m tryigng to take screenshot. I’m using Playwright 1.42.0. I’ve investigated logs using DEBUG=pw:* and i can see that right after calling page.screenshot playwright logs

pw:api waiting for fonts to load...

which is followed by a bunch of pw:protocol SEND {"id": XYZ (...) "document.fonts.ready" (...)

usually these SEND requests recieve immediate response like:

pw:protocol RECV {"id" XYZ (...)

but sometimes it takes several minutes - this is clearly causing problems and leads to hanging screenshot method.

Ofc screenshot method throws a timeout but subsequent screenshot calls from the same browser context seem to be affected and it’s basically not possible to capture screenshot anymore.

It seems to be somewhat related with #29968

I hope that this will help to find the root cause and fix the problem…