Full-page screenshots with lazy-loaded images: why they come out blank and how to fix it
You take a full-page screenshot, open the PNG, and the top of the page looks fine. Further down there are grey rectangles, empty cards and blank gaps where product photos should be. Nothing errored. The browser simply never loaded those images, because nobody scrolled to them.
This is one of the most common headless-browser questions, and the usual answers ("add a delay", "wait for network idle") do not fix it. We built a test page with three kinds of lazy loading, measured six capture strategies against it, then checked the winner on a real news homepage. Everything below was run on 20 November 2026 with Playwright and Chromium, and the final script is short enough to drop into any project.
Why full-page screenshots miss lazy-loaded images
Modern pages do not load every image up front. They load what is near the visible area and fetch the rest as you scroll. There are three common mechanisms:
- Native lazy loading:
<img loading="lazy">. The browser itself decides when to fetch, based on distance from the viewport. - JavaScript lazy loading: the real URL sits in
data-src, and anIntersectionObservercopies it intosrcwhen the element scrolls into view. Most lazy-load libraries and many frameworks work this way. - Lazy CSS backgrounds: the same observer pattern, but it sets
background-imageon adiv. There is no<img>element at all.
A full-page screenshot does not scroll the page. Playwright's fullPage: true and Puppeteer's equivalent capture the whole document height, but from the page's point of view the user is still at the top. Observers never fire, and native lazy images further than the browser's loading distance never start. The layout reserves space for them (if the site set width and height), so you get correctly sized holes.
Waiting does not help, because nothing is pending. The page is idle and happy; it is waiting for a scroll that never comes.
The test page
To measure this rather than guess, we made a 30-section page: 10 native lazy images, 10 IntersectionObserver images using data-src, and 10 lazy CSS backgrounds. It was served locally with an artificial 1.5-second delay on every image, which is roughly what you see from a slow CDN or a busy origin. The viewport was 1280 by 800, and the finished page is 14,614 pixels tall.
We then checked each screenshot by sampling the pixel at the centre of every image slot. A slot counts as visible only if it is not blank or placeholder grey in the actual PNG, which is what a person would see.
Six strategies, measured
| Strategy | Image slots visible | Time |
|---|---|---|
goto (load event) then full-page screenshot |
0 / 30 | 0.3 s |
Wait for networkidle |
4 / 30 | 2.4 s |
| Fixed 3-second delay | 4 / 30 | 3.4 s |
Set every loading="lazy" to eager, wait for images |
11 / 30 | 3.8 s |
| Scroll through the page, screenshot straight away | 12 / 30 | 3.8 s |
| Resize the viewport to the full page height | 30 / 30 | 8.3 s |
| Scroll through, then wait for images and network idle | 30 / 30 | 8.6 s |
A few things stand out:
- Network idle and fixed delays get stuck at 4. Those are the native lazy images Chromium was willing to fetch near the top. Waiting longer changes nothing, because nothing else has been asked for.
- Forcing
loading="eager"only fixes native lazy images. It got all 10 of those plus the one JavaScript image that was already on screen, and none of the CSS backgrounds. Sites using a lazy-load library are untouched by it. - Scrolling alone is not enough when images are slow. The scroll triggered every request, but the screenshot was taken while most responses were still in flight. With a fast local server (0.4 s per image) the same strategy got all 30, which is why it often works on a laptop and fails in production.
- Two approaches got everything: a giant viewport, and scroll-then-wait. They are not equally safe.
Why not just use a giant viewport
Setting the viewport to the page height puts every element "on screen" at once, so every observer fires. It worked on the test page. Then we added a common hero section, height: 100vh, to the top of the same page and tried again:
| Strategy | Hero height | Page height |
|---|---|---|
| Normal 800 px viewport, scroll through | 800 px | 15,334 px |
| Viewport resized to page height | 15,334 px | 29,868 px |
The hero grew to the size of the new viewport, pushed everything down, and doubled the page. Anything sized in vh units, full-screen modals, and "sticky until the bottom" elements behave the same way. The screenshot is technically complete and visually wrong. Scrolling at a normal viewport size keeps the layout the site was designed for, so that is the approach to build on.
A full-page capture script that waits for lazy content
Here is the script we ended up with. It scrolls in steps of 80% of the viewport (so no band of the page is skipped), keeps going while the page grows, gives infinite feeds a chance to append more, caps the height so a feed cannot run forever, then waits for images and for the network to go quiet before capturing.
// capture.mjs: full-page screenshot that waits for lazy-loaded content.
// Usage: node capture.mjs <url> <out.png>
import { chromium } from "playwright";
const MAX_HEIGHT = 20000; // stop scrolling infinite feeds here
const STEP_RATIO = 0.8; // scroll 80% of a viewport per step, so nothing is skipped
const PAUSE_MS = 200; // give IntersectionObserver callbacks time to fire
const SETTLE_MS = 10000; // max wait for images after scrolling
async function scrollThrough(page) {
await page.evaluate(async ({ maxHeight, stepRatio, pauseMs }) => {
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const step = Math.max(200, Math.floor(window.innerHeight * stepRatio));
let y = 0;
let idleChecks = 0;
// Re-read scrollHeight every step: pages grow as content loads.
while (y < maxHeight) {
const bottom = Math.min(document.documentElement.scrollHeight, maxHeight);
if (y < bottom) {
window.scrollTo(0, y);
await sleep(pauseMs);
y += step;
idleChecks = 0;
} else if (idleChecks < 3) {
// At the bottom: give infinite feeds a moment to append more content.
window.scrollTo(0, bottom);
await sleep(500);
idleChecks++;
} else break;
}
window.scrollTo(0, 0);
}, { maxHeight: MAX_HEIGHT, stepRatio: STEP_RATIO, pauseMs: PAUSE_MS });
}
async function waitForImages(page) {
await page.evaluate(async (timeoutMs) => {
// Native lazy images that are still pending: make them eager so they start now.
for (const img of document.querySelectorAll('img[loading="lazy"]')) img.loading = "eager";
const pending = [...document.images]
.filter((img) => !img.complete)
.map((img) => new Promise((r) => {
img.addEventListener("load", r, { once: true });
img.addEventListener("error", r, { once: true }); // a broken image must not hang the capture
}));
await Promise.race([Promise.all(pending), new Promise((r) => setTimeout(r, timeoutMs))]);
}, SETTLE_MS);
// CSS background images and late XHR content have no load event to wait on: wait for the network.
await page.waitForLoadState("networkidle", { timeout: SETTLE_MS }).catch(() => {});
}
export async function capture(url, path, { width = 1280, height = 800 } = {}) {
const browser = await chromium.launch();
try {
const page = await browser.newPage({ viewport: { width, height } });
await page.goto(url, { waitUntil: "load", timeout: 30000 });
await scrollThrough(page);
await waitForImages(page);
await page.waitForTimeout(300); // let sticky headers and scroll-linked animations reset at the top
const pageHeight = await page.evaluate(() => document.documentElement.scrollHeight);
if (pageHeight > MAX_HEIGHT) {
await page.screenshot({ path, fullPage: true, clip: { x: 0, y: 0, width, height: MAX_HEIGHT } });
} else {
await page.screenshot({ path, fullPage: true });
}
return { pageHeight, images: await page.evaluate(() => [...document.images].filter((i) => i.complete && i.naturalWidth > 0).length) };
} finally {
await browser.close();
}
}
if (import.meta.url === `file://${process.argv[1]}`) {
const [url, out = "page.png"] = process.argv.slice(2);
const t = Date.now();
const r = await capture(url, out);
console.log(`${out}: ${r.pageHeight}px tall, ${r.images} images loaded, ${Date.now() - t} ms`);
}
Install and run it with:
npm install playwright
npx playwright install chromium
node capture.mjs https://example.com page.png
What each step is for
Scrolling in steps with a pause. IntersectionObserver callbacks run asynchronously. If you jump straight to the bottom, elements you passed may never be reported as intersecting, so the loop stops at each position for 200 ms. Stepping by 80% of the viewport leaves an overlap, which matters for observers with no rootMargin.
Re-reading the height on every step. Pages grow while you scroll: images without explicit dimensions expand, and feeds append cards. A loop that measures scrollHeight once at the start stops short.
The idle checks at the bottom. Our first version stopped as soon as it reached the bottom. On an infinite-feed test page (10 cards appended each time a sentinel at the bottom becomes visible, after a 300 ms delay) it captured 8,498 pixels and missed everything after the first two batches. Waiting up to three times for 500 ms at the bottom lets the feed respond; with that change the same page grew until it hit the 20,000-pixel cap, and the screenshot was clipped to exactly that height.
Scrolling back to the top. Sticky headers, "back to top" buttons and scroll-triggered animations are usually positioned for the top of the page. Capturing from the top with a short pause gives the most natural-looking result.
Waiting for images, with a timeout. The load and error listeners cover every <img>, including ones the scroll just triggered. A broken image fires error, so it cannot hang the capture. The overall 10-second cap protects you from pages that never finish.
Network idle after that. CSS backgrounds and data fetched by scripts have no element-level load event, so the last step waits for the network to be quiet for a moment. It is wrapped in catch because pages with analytics beacons or long-polling may never reach idle, and a slightly early capture is better than a timeout.
Does it work on a real site?
The test page is deliberately simple, so we also ran a plain capture and the script against the homepage of a large news site, which lazy-loads most of its images (149 of 167 <img> elements had loading="lazy").
| Images loaded at capture time | Time | |
|---|---|---|
goto then full-page screenshot |
49 of 167 | 16.9 s |
capture.mjs |
164 of 167 | 37.4 s |
The cost is time. The plain capture was already slow because of the page's own scripts, and scrolling plus waiting more than doubled it. That is the honest trade-off: complete screenshots of long, image-heavy pages take tens of seconds, not a few hundred milliseconds. Batch them, run several in parallel, and cache the results rather than capturing on demand in a request path. Our post on website thumbnails and link previews covers batching and caching.
Two other pages we tried (a design blog's article index and a developer documentation article) loaded all their images with or without the script, so the extra time bought nothing there. One photo-site page returned an empty 800-pixel page with no images to headless Chromium in both modes. That looks like bot detection rather than lazy loading (we did not dig further), and no amount of scrolling fixes it.
The same thing in Puppeteer
The work happens inside page.evaluate, so it ports directly. This shorter Puppeteer version uses a single scroll pass (no infinite-feed handling) and Puppeteer's waitForNetworkIdle. It also captured 30 of 30 slots on the test page.
import puppeteer from "puppeteer-core";
const [url, out = "page.png"] = process.argv.slice(2);
const browser = await puppeteer.launch({ executablePath: process.env.CHROME_PATH, headless: true,
args: ["--no-sandbox"] }); // --no-sandbox only because this container runs as root
try {
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 800 });
await page.goto(url, { waitUntil: "load", timeout: 30000 });
// 1. Scroll in steps so IntersectionObserver-based loaders fire.
await page.evaluate(async () => {
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const step = Math.floor(window.innerHeight * 0.8);
for (let y = 0; y < Math.min(document.documentElement.scrollHeight, 20000); y += step) {
window.scrollTo(0, y);
await sleep(200);
}
window.scrollTo(0, 0);
});
// 2. Wait for every <img> to finish (or fail), max 10 s.
await page.evaluate(async () => {
const pending = [...document.images].filter((i) => !i.complete).map((i) =>
new Promise((r) => { i.addEventListener("load", r, { once: true }); i.addEventListener("error", r, { once: true }); }));
await Promise.race([Promise.all(pending), new Promise((r) => setTimeout(r, 10000))]);
});
// 3. Then for the network to go quiet (CSS backgrounds, late XHR).
await page.waitForNetworkIdle({ idleTime: 500, timeout: 10000 }).catch(() => {});
await page.screenshot({ path: out, fullPage: true });
} finally {
await browser.close();
}
puppeteer-core needs a Chrome path in CHROME_PATH; if you install the full puppeteer package instead, drop executablePath and it uses its bundled browser. Leave out --no-sandbox unless you run as root in a container.
Problems scrolling will not fix
- Content that loads on hover or click, such as image carousels where only the first slide is in the DOM. You have to click through them or accept the first slide.
- Bot protection and consent walls. If the screenshot shows a challenge page or a cookie banner over everything, deal with that first. Scrolling a challenge page captures a long challenge page.
- Very tall pages. Image formats and browsers have practical size limits, and a 60,000-pixel PNG is rarely what anyone wants. Cap the height (as the script does) or capture a PDF instead.
- Animations that fade content in. Elements that animate on scroll may be mid-transition. A short final pause helps; injecting CSS that sets
animation: noneandtransition: noneon everything is the heavier fix.
Or let the API run the browser
If you would rather not maintain a browser fleet, the Siftwright screenshot API renders pages in Chromium and returns a PNG, JPEG or PDF with fullPage on by default. For pages that load content late, it accepts waitForSelector (wait for a CSS selector to appear) and delaySec (an extra fixed wait of up to 10 seconds). As the measurements above show, a delay on its own does not trigger scroll-based loaders, so a selector near the bottom of the page, such as the footer or the last card, is the better choice when you know the site. We did not re-run the API against the test page for this post; if a capture still comes back with gaps, send the URL to support@siftwright.com and we will look at it.
You can try a capture for free with the website screenshot tool, and the screenshot API tutorial has request examples in Python and Node.js.
Related guides
Website screenshot API in Python and Node.js: full-page, mobile, retina and PDF
How to capture website screenshots from code without running your own headless browser fleet. Working Python and Node.js examples for full-page, mobile, retina and PDF captures, late-loading pages, and a batch script with retries.
Visual regression testing with a screenshot API and pixel diffs in Python
Build a small visual regression check in Python. Capture full-page screenshots with an API, diff them against baselines with Pillow, ignore dynamic regions and fail on real layout changes. Tested, with the threshold mistake we hit and fixed.
Get the next guide by email
Practical tutorials on transcripts, screenshots, news data and agent tooling. A couple of emails a month at most.