JavaScript / TypeScript

JavaScript / TypeScript SDK

Official SDK for the ScreenshotCenter API. Capture screenshots, PDFs, HTML, and video — without writing raw HTTP calls.

Installation

terminal
npm install screenshotcenter
Package coming soon to npmnpmjs.com/package/screenshotcenter

Quick start

index.mjs
import { ScreenshotCenterClient } from 'screenshotcenter';

const client = new ScreenshotCenterClient({ apiKey: 'YOUR_API_KEY' });

// Request a screenshot and wait for it to finish
const screenshot = await client.screenshot.create({ url: 'https://example.com' });
const result = await client.waitFor(screenshot.id);

console.log(result.status);       // 'finished'
console.log(result.storage_url);  // S3 URL

More examples

Full-page screenshot in a specific country
import { ScreenshotCenterClient } from 'screenshotcenter';

const client = new ScreenshotCenterClient({ apiKey: 'YOUR_API_KEY' });

const screenshot = await client.screenshot.create({
  url: 'https://example.com',
  size: 'page',        // capture the full scrollable page
  country: 'fr',       // route through a French browser client
  language: 'fr-FR',
  timezone: 'Europe/Paris',
});

const result = await client.waitFor(screenshot.id);
await client.screenshot.saveImage(result.id, './output/fr-full.png');
Generate a PDF
import { ScreenshotCenterClient } from 'screenshotcenter';

const client = new ScreenshotCenterClient({ apiKey: 'YOUR_API_KEY' });

const screenshot = await client.screenshot.create({
  url: 'https://example.com/report',
  pdf: true,
  pdf_landscape: true,
  pdf_format: 'A4',
});

const result = await client.waitFor(screenshot.id);
await client.screenshot.savePDF(result.id, './output/report.pdf');
Error handling
import {
  ScreenshotCenterClient,
  ApiError,
  TimeoutError,
  ScreenshotFailedError,
} from 'screenshotcenter';

const client = new ScreenshotCenterClient({ apiKey: 'YOUR_API_KEY' });

try {
  const screenshot = await client.screenshot.create({ url: 'https://example.com' });
  const result = await client.waitFor(screenshot.id, { timeout: 60_000 });
} catch (err) {
  if (err instanceof ApiError) {
    console.error('API error ' + err.status + ': ' + err.message);
  } else if (err instanceof TimeoutError) {
    console.error('Timed out for screenshot ' + err.screenshotId);
  } else if (err instanceof ScreenshotFailedError) {
    console.error('Screenshot failed: ' + err.screenshotError);
  }
}

Resources