New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

snapapi-js

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snapapi-js

Official JavaScript/TypeScript SDK for SnapAPI - Screenshot & PDF generation API

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

snapapi-js

Official JavaScript/TypeScript SDK for SnapAPI — a fast, reliable Screenshot & PDF generation API powered by headless Chrome.

Free tier available — 5 screenshots free, no credit card required. Get your API key at opspawn.com/snapapi

npm version License: MIT

Quick Start

npm install snapapi-js
const SnapAPI = require('snapapi-js');

const snap = new SnapAPI({ apiKey: 'YOUR_API_KEY' });
const image = await snap.screenshot('https://example.com');
require('fs').writeFileSync('screenshot.png', image);

That's it. Three lines of code to capture any webpage as a PNG.

Installation

# npm
npm install snapapi-js

# yarn
yarn add snapapi-js

# pnpm
pnpm add snapapi-js

Usage

Screenshot a URL

const SnapAPI = require('snapapi-js');
const fs = require('fs');

const snap = new SnapAPI({ apiKey: 'YOUR_API_KEY' });

// Basic screenshot
const png = await snap.screenshot('https://github.com');
fs.writeFileSync('github.png', png);

// Full-page screenshot in JPEG
const jpg = await snap.screenshot('https://example.com', {
  fullPage: true,
  format: 'jpeg',
  quality: 85,
  width: 1440,
  height: 900,
});
fs.writeFileSync('full-page.jpg', jpg);

// Screenshot a specific element
const element = await snap.screenshot('https://example.com', {
  selector: '#hero-section',
});
fs.writeFileSync('hero.png', element);

Generate PDF from a URL

const snap = new SnapAPI({ apiKey: 'YOUR_API_KEY' });

// Basic PDF (A4)
const pdf = await snap.pdf('https://example.com');
fs.writeFileSync('page.pdf', pdf);

// Custom PDF options
const report = await snap.pdf('https://my-report.com', {
  format: 'Letter',
  landscape: true,
  marginTop: '20mm',
  marginBottom: '20mm',
  printBackground: true,
});
fs.writeFileSync('report.pdf', report);

Render from HTML

const snap = new SnapAPI({ apiKey: 'YOUR_API_KEY' });

const html = `
  <html>
    <body style="background: #1a1a2e; color: white; padding: 40px; font-family: sans-serif;">
      <h1>Hello from SnapAPI!</h1>
      <p>Generated at ${new Date().toISOString()}</p>
    </body>
  </html>
`;

// Screenshot from HTML
const image = await snap.fromHTML(html);
fs.writeFileSync('from-html.png', image);

// PDF from HTML
const pdf = await snap.fromHTML(html, { type: 'pdf', format: 'A4' });
fs.writeFileSync('from-html.pdf', pdf);

TypeScript

import SnapAPI, { ScreenshotOptions, PDFOptions } from 'snapapi-js';

const snap = new SnapAPI({ apiKey: 'YOUR_API_KEY' });

const options: ScreenshotOptions = {
  width: 1280,
  height: 800,
  fullPage: true,
  format: 'png',
};

const buffer: Buffer = await snap.screenshot('https://example.com', options);

API Reference

new SnapAPI(options)

OptionTypeDefaultDescription
apiKeystringrequiredYour SnapAPI key
baseUrlstring'https://api.opspawn.com'API base URL
timeoutnumber30000Request timeout in ms

snap.screenshot(url, options?)

Captures a screenshot of the given URL.

Returns: Promise<Buffer> — PNG or JPEG image buffer

OptionTypeDefaultDescription
widthnumber1280Viewport width in pixels
heightnumber800Viewport height in pixels
format'png' | 'jpeg''png'Output image format
qualitynumber90JPEG quality (1-100)
fullPagebooleanfalseCapture full scroll height
selectorstringCSS selector for element capture
delaynumber0Wait delay in ms before capture
darkModebooleanfalseEnable dark mode emulation
deviceScaleFactor1 | 2 | 31Device pixel ratio

snap.pdf(url, options?)

Generates a PDF from the given URL.

Returns: Promise<Buffer> — PDF buffer

OptionTypeDefaultDescription
formatstring'A4'Paper format ('A4', 'Letter', 'Legal', 'A3', 'Tabloid')
landscapebooleanfalseLandscape orientation
printBackgroundbooleantruePrint CSS backgrounds
marginTopstring'10mm'Top margin
marginBottomstring'10mm'Bottom margin
marginLeftstring'10mm'Left margin
marginRightstring'10mm'Right margin
displayHeaderFooterbooleanfalseShow header/footer
headerTemplatestringHTML header template
footerTemplatestringHTML footer template
delaynumber0Wait delay in ms before capture

snap.fromHTML(html, options?)

Renders a screenshot or PDF from raw HTML content.

Returns: Promise<Buffer> — Image or PDF buffer

Accepts all options from screenshot() and pdf(), plus:

OptionTypeDefaultDescription
type'screenshot' | 'pdf''screenshot'Output type

Error Handling

try {
  const image = await snap.screenshot('https://example.com');
} catch (err) {
  if (err.message.includes('Invalid API key')) {
    // Get your key at https://opspawn.com/snapapi
  } else if (err.message.includes('Usage limit')) {
    // Upgrade your plan at https://opspawn.com/snapapi
  } else if (err.message.includes('Rate limit')) {
    // Slow down requests or upgrade plan
  } else {
    console.error(err.message);
  }
}

Pricing

PlanScreenshotsPDFPrice
Free5/month5/monthFree, no credit card
Pro1,000/month1,000/month$19/month
Business10,000/month10,000/month$99/month

Get your API key at opspawn.com/snapapi →

Why SnapAPI?

  • Faster than self-hosting — No Puppeteer/Playwright setup, no browser process management
  • Reliable — Managed infrastructure, 99.9% uptime SLA
  • Simple — One npm install, three lines of code
  • TypeScript-ready — Full type definitions included
  • Drop-in replacement — Designed to replace complex Puppeteer screenshot pipelines

License

MIT — see LICENSE for details.

Built by OpSpawn — autonomous AI agent infrastructure.

Keywords

screenshot

FAQs

Package last updated on 08 Mar 2026

Related posts