snaprender
v0.2.4
Published
Official Node.js SDK for SnapRender Screenshot API
Maintainers
Readme
snaprender
Official Node.js SDK for the SnapRender Screenshot API — capture pixel-perfect screenshots of any webpage with a single API call.
500 free screenshots/month — Get your API key
Features
- Multiple output formats — PNG, JPEG, WebP, and PDF
- Device emulation — iPhone, iPad, Pixel, and more presets
- Dark mode — Capture pages with
prefers-color-scheme: dark - Ad blocking — Remove ads automatically before capture
- Cookie banner removal — Clean screenshots without consent popups
- Smart caching — Configurable CDN cache with TTL control
- Full-page captures — Screenshot the entire scrollable page
Install
npm install snaprenderQuick Start
import SnapRender from 'snaprender';
import fs from 'node:fs';
const snap = new SnapRender({ apiKey: 'sk_live_...' });
// Capture a screenshot
const buffer = await snap.capture({ url: 'https://example.com' });
fs.writeFileSync('screenshot.png', buffer);
// Capture as JPEG with options
const jpg = await snap.capture({
url: 'https://example.com',
format: 'jpeg',
width: 1920,
height: 1080,
fullPage: true,
darkMode: true,
quality: 95,
});
// Check cache status
const info = await snap.info({ url: 'https://example.com' });
console.log(info.cached); // true/false
console.log(info.expiresAt); // ISO date string (when cached)
// Get usage
const usage = await snap.usage();
console.log(`${usage.used}/${usage.limit} screenshots used`);API
new SnapRender(options)
| Option | Type | Required | Default |
|--------|------|----------|---------|
| apiKey | string | Yes | — |
| baseUrl | string | No | https://app.snap-render.com |
snap.capture(options) -> Promise<Buffer>
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| url | string | — | URL to capture (required) |
| format | 'png' \| 'jpeg' \| 'webp' \| 'pdf' | 'png' | Output format |
| width | number | 1280 | Viewport width |
| height | number | 800 | Viewport height |
| fullPage | boolean | false | Capture full scrollable page |
| quality | number | 90 | JPEG/WebP quality (1-100) |
| delay | number | 0 | Wait ms after page load |
| darkMode | boolean | false | Emulate dark mode |
| blockAds | boolean | true | Block ad networks |
| blockCookieBanners | boolean | true | Remove cookie banners |
| device | string | — | Device preset ('iphone_14', 'iphone_15_pro', 'pixel_7', 'ipad_pro', 'macbook_pro') |
| hideSelectors | string | — | Comma-separated CSS selectors to hide |
| clickSelector | string | — | CSS selector to click before capture |
| userAgent | string | — | Custom user agent string |
| cache | boolean | true | Use cache |
| cacheTtl | number | 86400 | Cache TTL in seconds |
| responseType | 'binary' \| 'json' | 'binary' | 'json' returns metadata + base64 data URI |
snap.info(options) -> Promise<CacheInfo>
Check if a screenshot is cached without capturing. Returns { url, cached, cacheKey, cachedAt?, expiresAt?, contentType? }.
snap.usage() -> Promise<UsageResponse>
Get current month's usage.
snap.usageDaily(days?) -> Promise<DailyUsage>
Get daily usage breakdown (default 30 days).
Error Handling
import { SnapRenderError } from 'snaprender';
try {
await snap.capture({ url: 'https://example.com' });
} catch (err) {
if (err instanceof SnapRenderError) {
console.log(err.code); // 'QUOTA_EXCEEDED'
console.log(err.status); // 429
console.log(err.message); // 'Monthly quota exceeded'
}
}Links
License
MIT
