October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Take Screenshots of Lazy-Loaded Pages with Playwright in Python

Scroll through lazy-loaded content, wait for the elements you need, then use Playwright’s full-page screenshot option. Includes Python code, edge cases, and a no-browser alternative.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To capture content that appears only after scrolling, scroll through the relevant page regions first, wait for the content you need to appear, and then call Playwright’s page.screenshot(path="page.png", full_page=True). The full_page option captures the page’s full scrollable extent; it does not, by itself, trigger or verify lazy loading.

Choose the screenshot method for the result you need

Need Python What it captures
Visible viewport saved to a file page.screenshot(path="page.png") The currently visible page area.
Full document saved to a file page.screenshot(path="page.png", full_page=True) The full scrollable page, as if it were a very tall screen.
One matching element saved to a file page.locator(".target").screenshot(path="target.png") The matching element; Playwright scrolls it into view first.
Screenshot bytes for processing in memory image_bytes = page.screenshot() Image data returned by the screenshot call rather than saved to a file.

For a whole page, use page.screenshot(..., full_page=True) after loading the required content. An element screenshot is useful for a particular region, but if that element is a scrollable container, its screenshot shows only the container’s currently scrolled portion.

As an Amazon Associate I earn from qualifying purchases.

Official references: Playwright Python screenshots and Playwright Python locator API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Scroll to trigger lazy loading, then capture

This synchronous Python pattern scrolls through the document in viewport-sized increments, returns to the top, and takes a full-page screenshot. Replace the example URL and the locator with ones appropriate to the page. The example uses a short delay as a fallback; a page-specific readiness condition is more dependable where one is available.

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page(viewport={"width": 1440, "height": 900})
    page.goto("https://example.com")

    # Wait for a meaningful page-specific landmark.
    page.locator("main").wait_for(state="visible")

    # Move through the document to trigger viewport-dependent loading.
    page.evaluate("""async () => {
        const step = Math.max(window.innerHeight, 500);
        for (let y = 0; y < document.body.scrollHeight; y += step) {
            window.scrollTo(0, y);
            await new Promise(resolve => setTimeout(resolve, 200));
        }
        window.scrollTo(0, 0);
    }""")

    page.screenshot(path="page.png", full_page=True)
    browser.close()

The 200 ms pause is illustrative, not a universal loading guarantee. Some pages need a longer wait; others do not need a fixed pause at all. When possible, wait for a known image, card, or other element that proves the relevant content has appeared before capturing. Playwright locator methods auto-wait for their documented conditions, but that does not mean every lazy-loaded image on a page is ready.

Verify images when they matter

If the page uses images as the key content, check the specific images you need rather than assuming that scrolling alone completed the work. For example, after scrolling to a target image, a page-specific check can wait for that image to be complete and have a nonzero natural width:

image = page.locator("img.product-photo").first
image.scroll_into_view_if_needed()
image.wait_for(state="visible")
page.wait_for_function("""selector => {
    const img = document.querySelector(selector);
    return img && img.complete && img.naturalWidth > 0;
}""", ".product-photo")

Adapt the selector and condition to the actual page: some sites replace placeholder elements, load images as CSS backgrounds, or render content in other ways. A successful wait for one image does not prove that all other images are ready.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a deliberate stopping rule for changing pages

The sample loop reads document.body.scrollHeight as it advances, so it can include some content that expands the document during scrolling. It is not an unlimited crawler. Infinite-scroll pages, pages with nested scroll containers, or pages that append content after a delay require a stopping rule suited to the page—for example, a known final item, a “load more” control becoming unavailable, or a maximum scroll depth. Without a defined end, there is no natural boundary for a complete screenshot.

Capture an element or process the image in memory

For a specific element, use its locator’s screenshot method. The locator is scrolled into view before the capture:

page.locator(".article-content").screenshot(path="article-content.png")

This does not turn a scrollable element into a capture of all its internal content. To capture the full document, use the page-level screenshot with full_page=True. For programmatic processing, omit path and use the returned bytes:

image_bytes = page.screenshot(full_page=True)

The screenshot API also supports options for image format, clipping, and quality. Locator screenshots document an option to disable animations; finite animations are fast-forwarded and infinite animations are canceled to their initial state for the capture, then resumed. Consult the screenshot documentation and locator API reference for the option details relevant to your installed Playwright version.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common problems and fixes

  • The full-page image has blank image slots. Full-page capture controls output dimensions, not lazy-load behavior. Scroll the relevant regions into view, then wait for the page-specific image or content condition before taking the screenshot.
  • The screenshot stops partway through a feed. An infinite or expanding page may not have a stable final height. Define what “complete” means, such as a specific final item or a maximum depth, and stop when that condition is met.
  • A list of results changes while being captured. locator.all() returns immediately; it does not wait for a dynamic list to finish loading. Wait for an explicit completion condition or stable, page-specific result before enumerating the locators.
  • The element screenshot shows only part of a panel. A locator screenshot of a scrollable container captures its currently scrolled content. Scroll within that container if you need another portion, or use a page-level full-page screenshot for the whole document.
  • A fixed pause works inconsistently. Network and rendering time varies by page and run. Replace arbitrary timing with a locator or image-completion condition where possible; there is no single wait strategy that guarantees lazy loading on every site.
  • The page has nested scrolling. Scrolling the window will not necessarily trigger content inside an independently scrollable panel. Identify that container and scroll it as well, then verify the target content before capture.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo provides a website screenshot API and MCP server. Its one-call API can return a screenshot or PDF; for this workflow, point it at the target URL and request the needed output settings. See the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

Before capture, ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers indicate the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up free for 1,000 screenshots a month with no card.

Frequently Asked Questions

Does full_page=True make Playwright load every lazy image?

No. It captures the full scrollable page extent, but you must trigger and verify deferred content before taking the screenshot.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can Playwright return a screenshot without writing a file?

Yes. Call page.screenshot() without a path argument to receive image bytes.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.