# How to take full-page screenshots of lazy-loaded pages

> A full-page capture doesn't scroll, so lazy images and sections stay empty. Scroll through the page first, wait for images, cap the height, then capture.

`fullPage: true` captures the whole document, but it doesn't scroll it. Images with `loading="lazy"` and sections that load when they enter the viewport stay as placeholders below the first screen. Scroll through the page in steps first, wait for the images that started loading, scroll back to the top, and cap the height before you capture.

## Scroll first, then capture

Save this as `scroll-through.js`:

```js
// Runs inside the page: scroll down in steps so lazy content loads, then back to the top.
export async function scrollThrough(maxHeight = 10_000) {
  const pause = (ms) => new Promise((done) => setTimeout(done, ms))
  for (let y = 0; y < Math.min(document.documentElement.scrollHeight, maxHeight); y += innerHeight * 0.8) {
    scrollTo(0, y)
    await pause(200)
  }
  // Lazy images the scroll did not reach (carousels, tabs) load now.
  for (const img of document.querySelectorAll('img[loading="lazy"]')) img.loading = 'eager'
  const pending = [...document.images].filter((img) => !img.complete)
  await Promise.race([
    Promise.all(pending.map((img) => new Promise((done) => (img.onload = img.onerror = done)))),
    pause(5000),
  ])
  scrollTo(0, 0)
  await pause(200)
}
```

Pass the same cap to the scroll and to the capture:

Playwright:

```js
import { chromium } from 'playwright'
import { scrollThrough } from './scroll-through.js'

const MAX_HEIGHT = 10_000
const url = process.argv[2]
const browser = await chromium.launch()
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } })
await page.goto(url, { waitUntil: 'load' })
await page.evaluate(scrollThrough, MAX_HEIGHT)
const height = await page.evaluate(() => document.documentElement.scrollHeight)
await page.screenshot({
  path: 'screenshot.png',
  fullPage: true,
  clip: { x: 0, y: 0, width: 1280, height: Math.min(height, MAX_HEIGHT) },
})
await browser.close()
```

Puppeteer:

```js
import puppeteer from 'puppeteer'
import { scrollThrough } from './scroll-through.js'

const MAX_HEIGHT = 10_000
const url = process.argv[2]
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.setViewport({ width: 1280, height: 800 })
await page.goto(url, { waitUntil: 'load' })
await page.evaluate(scrollThrough, MAX_HEIGHT)
const height = await page.evaluate(() => document.documentElement.scrollHeight)
// clip reaches below the viewport; Puppeteer rejects clip together with fullPage.
await page.screenshot({
  path: 'screenshot.png',
  clip: { x: 0, y: 0, width: 1280, height: Math.min(height, MAX_HEIGHT) },
})
await browser.close()
```

Each step moves 80% of a screen, so steps overlap and nothing is skipped. The 200 ms pause gives scroll handlers and `IntersectionObserver` callbacks time to run; raise it for slow sites. Images that are still loading get up to 5 seconds before the capture goes ahead without them.

## Cap the height

Infinite feeds grow while you scroll, and some pages are tens of thousands of pixels tall. Cap the scroll and the capture at the same height. Image formats have hard limits too: a WebP image is at most 16,383 pixels on each side, and a JPEG at most 65,535.

## When it still goes wrong

- **Only the first screen has content.** Smooth-scrolling libraries put the page in a fixed wrapper as tall as the viewport and move it with transforms. The document is tall, but the wrapper clips everything below the first screen. Make the viewport as tall as the page and take a normal screenshot instead (code below).
- **Sections are blank after scrolling back up.** Some reveal-on-scroll effects reset when a section leaves the viewport. Override the site's reveal class with CSS, or use the tall viewport.
- **A tall viewport stretches the hero.** Sections sized in `vh` grow with the viewport, so a `100vh` hero fills the whole image. Use the tall viewport only when the normal capture fails.

Playwright:

```js
// Continues the script above: after scrollThrough(), instead of the full-page screenshot.
const height = await page.evaluate(() => document.documentElement.scrollHeight)
await page.setViewportSize({ width: 1280, height: Math.min(height, MAX_HEIGHT) })
await page.screenshot({ path: 'screenshot.png' })
```

Puppeteer:

```js
// Continues the script above: after scrollThrough(), instead of the full-page screenshot.
const height = await page.evaluate(() => document.documentElement.scrollHeight)
await page.setViewport({ width: 1280, height: Math.min(height, MAX_HEIGHT) })
await page.screenshot({ path: 'screenshot.png' })
```

## With Shotfly

`full_page=true` scrolls lazy content into view before the capture. `full_page_max_height` sets the cap: 10,000 CSS pixels by default, 20,000 at most. For WebP the cap is lowered to fit 16,383 image pixels, and a taller page is cut at the bottom rather than failing.

```bash
curl -G "https://api.shotfly.dev/v1/screenshot" --data-urlencode "url=https://example.com" \
  -d full_page=true -d full_page_max_height=15000 \
  -H "Authorization: Bearer $SHOTFLY_SECRET_KEY" -o page.png
```

## Related

- [Web archiving](https://shotfly.dev/use-cases/web-archiving)
- [Website screenshot API](https://shotfly.dev/use-cases/website-screenshot-api)
- [The full_page parameter](https://shotfly.dev/docs/parameters#full_page)
- [Fixing blank screenshots](https://shotfly.dev/guides/fix-blank-screenshots)
- [Screenshot API comparison](https://shotfly.dev/compare)

---

Source: https://shotfly.dev/guides/full-page-screenshots-lazy-loading · Last updated 2026-12-01
