snapapi-sdk
v1.4.0
Published
Official Node.js SDK for SnapAPI — screenshot, analyze, PDF, metadata, monitors, and more
Maintainers
Readme
snapapi-js
Official Node.js SDK for SnapAPI — capture any website as an image.
Zero dependencies. Uses native fetch (Node 18+).
Install
npm install snapapi-jsQuick Start
const SnapAPI = require('snapapi-js');
const fs = require('fs');
const snap = new SnapAPI('snap_your_key_here');
// Basic screenshot
const image = await snap.screenshot('example.com');
fs.writeFileSync('screenshot.png', image);
// With options
const webp = await snap.screenshot('example.com', {
format: 'webp',
darkMode: true,
fullPage: true,
});
fs.writeFileSync('screenshot.webp', webp);
// Mobile screenshot (iPhone 14)
const mobile = await snap.screenshot('example.com', { device: 'iphone14' });
// Capture a specific element
const header = await snap.screenshot('example.com', { selector: 'header' });
// Get structured page data (great for AI agents)
const meta = await snap.screenshot('example.com', { meta: true });
console.log(meta.title, meta.description);
console.log(meta.headings); // [{level: 1, text: "..."}, ...]
console.log(meta.links); // [{text: "...", href: "..."}, ...]
console.log(meta.text); // Extracted visible text (first 2000 chars)
// Check your usage
const usage = await snap.usage();
console.log(`${usage.usage.count} screenshots this month`);Screenshot Options
| Option | Type | Description |
|------------|---------|--------------------------------------|
| width | number | Viewport width in pixels |
| height | number | Viewport height in pixels |
| format | string | "png", "jpeg", or "webp" |
| quality | number | Image quality 1-100 (jpeg/webp only) |
| fullPage | boolean | Capture the full scrollable page |
| delay | number | Wait ms before capturing |
| darkMode | boolean | Emulate dark color scheme |
| blockAds | boolean | Block common ad networks |
| cache | boolean | Use cached result if available |
| selector | string | CSS selector to capture |
| device | string | Device preset: "iphone14", "pixel7", "ipad", "desktop", etc. |
| meta | boolean | Return page metadata as JSON |
Error Handling
const { SnapAPIError } = require('snapapi-js');
try {
const image = await snap.screenshot('example.com');
} catch (err) {
if (err instanceof SnapAPIError) {
console.error(err.status, err.message);
}
}Scheduled Monitors
// Create a monitor — captures every 15 minutes
const monitor = await snap.createMonitor({
url: 'https://example.com',
name: 'Homepage',
interval_minutes: 15,
params: { format: 'webp', fullPage: true },
webhook_url: 'https://your-app.com/webhook',
});
// List all monitors
const monitors = await snap.listMonitors();
// Pause / resume
await snap.updateMonitor(monitor.id, { status: 'paused' });
await snap.updateMonitor(monitor.id, { status: 'active' });
// Browse snapshots
const { snapshots } = await snap.listSnapshots(monitor.id, { limit: 10 });
// Download a snapshot image
const image = await snap.getSnapshot(monitor.id, snapshots[0].id);
fs.writeFileSync('snapshot.webp', image);
// Delete a monitor (cascades to snapshots)
await snap.deleteMonitor(monitor.id);Monitors require Starter tier or above. See pricing for limits.
Account Management
// Full account info
const account = await snap.account();
// Update settings
await snap.updateSettings({ name: 'My App' });
// Sign up (no API key needed)
const snap = new SnapAPI('placeholder');
const result = await snap.signup('[email protected]');
console.log(result.key); // Your new API keyLicense
MIT
