Guides · Node.js · built-in fetch

Capture very tall pages as numbered tiles in Node.js with built-in fetch

A single image has a height cap (20,000 CSS px) because somewhere past that, image viewers and memory both give up. "tile": true is the opt-in for pages that run past it: instead of cutting the capture off, the API returns a ZIP of numbered PNG tiles that cover the entire document.

Below is a complete, runnable Node.js program using built-in fetch, no third-party dependency needed. It reads your API key from the SNAPDOK_KEY environment variable — free keys take about thirty seconds and need no card.

import { writeFile } from "node:fs/promises";

const res = await fetch("https://snapdok.io/v1/render", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.SNAPDOK_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    url: "https://your-app.com/changelog",
    format: "png",
    full_page: true,
    tile: true,
  }),
});

if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
await writeFile("page-tiles.zip", Buffer.from(await res.arrayBuffer()));
console.log(res.headers.get("x-tiles"), "// how many parts are in the ZIP");

The tiles overlap on purpose: each part starts 80 px above where the previous one ended, so the seam appears in both images and nothing can fall into a gap — line up the repeated rows and you have the whole page. The archive includes a README stating each part's y-range, and the response carries the numbers too: X-Tiles (count), X-Tile-Overlap (the 80 px), and X-Page-Height.

Note the response type changes: with tiling you receive application/zip, not image/png — code that assumes an image must branch on Content-Type. Pages short enough for one image return a plain PNG even with tile set, so the branch is required, not theoretical. That asymmetry is deliberate: a screenshot is one image to almost everyone, so the archive only happens when you asked for it and the page needs it.

Same endpoint, one more trick: if the page you are rendering has a form on it, adding "pdf_forms": true to a PDF render brings it back with real, fillable AcroForm fields — a PDF people can type into, not a picture of one. How that works.

Notes for built-in fetch

No dependency needed: fetch is global from Node 18 onward (snapdok's own test suite uses it). The binary-safety detail is res.arrayBuffer()Buffer.from(...) — reaching for res.text() is the classic way to corrupt a PDF in Node. fetch does not reject on HTTP error statuses, so the res.ok check is load-bearing: without it, an expired key writes a 40-byte JSON error to disk with a .pdf extension.

Response headers worth reading

HeaderMeaning
Content-Typeapplication/zip when tiled, image/png when not needed.
X-TilesNumber of parts in the archive.
X-Tile-OverlapVertical overlap between parts, in CSS px.

Full parameter reference: the docs. Hard numbers on caps and timeouts: limits.

Related guides

Same task, other stacks

More with Node.js + built-in fetch