fullPage: true looks like the easy option in Puppeteer. Ask for the whole
document instead of the viewport, get a taller image. In practice a full-page
capture has failure modes a viewport capture does not, and two of them are
still open in
Screenshotline.
Below the fold, nothing has loaded
Most sites lazy-load images with IntersectionObserver. If nothing ever
scrolled, nothing ever intersected, so the bottom three quarters of your
full-page capture is placeholders and empty boxes. The page looks loaded to the
renderer and looks broken to the reader.
The fix is to scroll the document before capturing, which is crude and universally necessary:
const step = window.innerHeight * 0.85;
for (let i = 0; i < limit; i += 1) {
window.scrollBy(0, step);
await sleep(120);
const height = document.body.scrollHeight;
const atBottom = window.scrollY + window.innerHeight >= height - 2;
if (atBottom && height === previousHeight) break;
previousHeight = height;
}
window.scrollTo(0, 0);
Three details carry their weight. The step is 85% of the viewport rather than a full screen, so observers near a boundary still fire. The loop stops when it reaches the bottom and the page stopped growing, which separates a finished page from one still appending. And it returns to the top before capturing, because the capture that follows expects the page at origin.
An infinite feed will hold your slot forever
A page that appends content every time you reach the bottom never satisfies "stopped growing". Left alone, the loop runs until something else kills it.
So it is bounded twice: a maximum number of scroll steps, and a wall-clock ceiling on the whole operation calculated from those steps. A wedged main thread must not hold a rendering slot open while the loop politely waits for a page that has stopped answering.
That gives a plain answer about infinite feeds: you get a bounded amount of them, deterministically, rather than a timeout.
PDF is a different capture, not a flag
The same render can come back as a PDF, and the capture step diverges:
capture = page.pdf({
printBackground: !options.omitBackground,
width: `${options.viewportWidth}px`,
height: options.fullPage ? undefined : `${options.viewportHeight}px`,
preferCSSPageSize: false,
});
Leaving height undefined for a full-page PDF is what makes it one long page
rather than paginated slices. printBackground defaults on, because a
screenshot without backgrounds is not what anyone means by a screenshot.
The blank detector is skipped for PDFs entirely, since bytes-per-pixel means nothing in that format.
The two bugs I have not fixed
Writing about your own open bugs is better than letting a customer find them, so here they are.
Sticky headers get stamped partway down the image. A position: sticky
header is drawn where it is at the moment the frame is taken, so in a tall
full-page capture it can appear in the middle of the page as well as at the
top. I found it capturing my own portfolio site. It is one of the most common
complaints about every screenshot API, including mine.
The fix idea is to return to the top after the scroll pass and then force fixed
and sticky elements to position: absolute before the capture, or hide the
ones that are not at the top. It is not shipped. Until it is, a full-page
capture of a site with a sticky header may contain the header twice.
Selector captures of scroll-reveal sections come out empty. Sites that fade
sections in with IntersectionObserver keep them at opacity: 0 until
scrolled into view. selector mode never scrolls, so selector=#products on
such a site returns an empty dark box. Full-page mode works, because it scrolls
first.
The fix idea is to scroll the target into view and let the settle run before capturing the element. Also not shipped.
What to copy
- Scroll before a full-page capture, in steps smaller than the viewport, and return to the top.
- Stop on bottom plus no growth, not on bottom alone.
- Bound it twice, by steps and by wall clock, because infinite feeds and wedged pages both exist.
- Treat PDF as its own capture path, and switch off the heuristics that only make sense for pixels.
- Publish your open bugs. Two of mine are above, and a customer reading them is better prepared than a customer discovering them.
The capture path is in
src/render.js.
full_page=true works on the free tier, 500 renders a month, and the same code
self-hosts with Docker.