Screenshot API for TypeScript: Node.js, Edge & Serverless
Use SnapAPI to capture screenshots from TypeScript. Works with Node.js, Deno, Bun, Cloudflare Workers, and Next.js. Typed SDK or plain fetch — zero browser dependencies.
Screenshot API for TypeScript Projects
SnapAPI integrates with TypeScript projects on Node.js, Deno, Bun, and edge runtimes without any SDK required. The API accepts standard HTTP requests and returns image bytes, JSON, or PDF depending on the endpoint. Full TypeScript type definitions are available in the official snapapi-js package, giving you autocomplete and type safety for all request parameters and response shapes.
Typed API Client with snapapi-js
npm install snapapi-js
// screenshot.ts
import SnapAPI from "snapapi-js";
const client = new SnapAPI({ apiKey: process.env.SNAPAPI_KEY! });
const result = await client.screenshot({
url: "https://example.com",
fullPage: true,
format: "png",
blockAds: true,
});
// result.image is a Buffer
await fs.writeFile("output.png", result.image);
console.log(`Captured: ${result.image.length} bytes`);The snapapi-js SDK provides full TypeScript types for all 9 endpoints: screenshot, scrape, extract, analyze, pdf, video, get_usage, list_devices, and ping. Each method returns a typed response object so TypeScript catches mismatched parameter types at compile time rather than at runtime.
Using fetch Directly
// Works in Node 18+, Deno, Bun, and Cloudflare Workers
const params = new URLSearchParams({
url: "https://example.com",
full_page: "true",
format: "jpeg",
quality: "85",
});
const res = await fetch(
`https://api.snapapi.pics/v1/screenshot?${params}`,
{ headers: { "X-Api-Key": process.env.SNAPAPI_KEY! } }
);
if (!res.ok) throw new Error(`SnapAPI error: ${res.status}`);
const buffer = Buffer.from(await res.arrayBuffer());
await fs.writeFile("screenshot.jpg", buffer);The native fetch approach works across all modern TypeScript runtimes and requires zero dependencies. Use it when you want to minimize bundle size in edge functions or keep your dependency tree clean in serverless deployments.
TypeScript on Edge and Serverless
Cloudflare Workers, Vercel Edge Functions, and Deno Deploy all support the Fetch API natively, making SnapAPI calls trivial from edge environments. Since SnapAPI handles the browser rendering on its own infrastructure, your edge function stays lightweight — there is no Chromium binary to bundle, no memory overhead, and no cold-start penalty from a large dependency.
For Next.js projects, call SnapAPI from API routes or server actions rather than client components. This keeps your API key server-side and allows you to cache responses in the Next.js data cache with fetch revalidation:
// app/api/preview/route.ts
export async function GET(req: Request) {
const url = new URL(req.url).searchParams.get("url");
const res = await fetch(
`https://api.snapapi.pics/v1/screenshot?url=${encodeURIComponent(url!)}&format=jpeg`,
{
headers: { "X-Api-Key": process.env.SNAPAPI_KEY! },
next: { revalidate: 3600 }, // cache for 1 hour
}
);
const image = await res.arrayBuffer();
return new Response(image, { headers: { "Content-Type": "image/jpeg" } });
}This pattern creates a URL preview endpoint that caches screenshots for an hour using Next.js built-in data caching. It is ideal for link-preview cards in a social feed or thumbnail generation for a CMS where content does not change frequently.