Shotfly

Guide

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

By the Shotfly team · Published 2026-12-01

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:

scroll-through.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:

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()

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

// 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' })

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.

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

Last updated 2026-12-01. Markdown version: /guides/full-page-screenshots-lazy-loading.md

Skip the browser plumbing

100 free screenshots a month. Failed captures cost nothing.

Get a free API key