npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

snapapi-js

v1.0.1

Published

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

Readme

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)

| Option | Type | Default | Description | |--------|------|---------|-------------| | apiKey | string | required | Your SnapAPI key | | baseUrl | string | 'https://api.opspawn.com' | API base URL | | timeout | number | 30000 | Request timeout in ms |


snap.screenshot(url, options?)

Captures a screenshot of the given URL.

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

| Option | Type | Default | Description | |--------|------|---------|-------------| | width | number | 1280 | Viewport width in pixels | | height | number | 800 | Viewport height in pixels | | format | 'png' \| 'jpeg' | 'png' | Output image format | | quality | number | 90 | JPEG quality (1-100) | | fullPage | boolean | false | Capture full scroll height | | selector | string | — | CSS selector for element capture | | delay | number | 0 | Wait delay in ms before capture | | darkMode | boolean | false | Enable dark mode emulation | | deviceScaleFactor | 1 \| 2 \| 3 | 1 | Device pixel ratio |


snap.pdf(url, options?)

Generates a PDF from the given URL.

Returns: Promise<Buffer> — PDF buffer

| Option | Type | Default | Description | |--------|------|---------|-------------| | format | string | 'A4' | Paper format ('A4', 'Letter', 'Legal', 'A3', 'Tabloid') | | landscape | boolean | false | Landscape orientation | | printBackground | boolean | true | Print CSS backgrounds | | marginTop | string | '10mm' | Top margin | | marginBottom | string | '10mm' | Bottom margin | | marginLeft | string | '10mm' | Left margin | | marginRight | string | '10mm' | Right margin | | displayHeaderFooter | boolean | false | Show header/footer | | headerTemplate | string | — | HTML header template | | footerTemplate | string | — | HTML footer template | | delay | number | 0 | Wait 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:

| Option | Type | Default | Description | |--------|------|---------|-------------| | 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

| Plan | Screenshots | PDF | Price | |------|-------------|-----|-------| | Free | 5/month | 5/month | Free, no credit card | | Pro | 1,000/month | 1,000/month | $19/month | | Business | 10,000/month | 10,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.