Skip to content

cwanglab/snapapi

Repository files navigation

SnapAPI

Screenshot any webpage via API in milliseconds.

Quick Start

Local Development

# Install dependencies
npm install

# Install Chromium for Playwright
npx playwright install chromium

# Copy environment config
cp .env.example .env

# Run in development mode
npm run dev

The server starts at http://localhost:3000.

Docker

# Build and run
docker compose up -d

# Or build manually
docker build -t snapapi .
docker run -p 3000:3000 --shm-size=1g snapapi

Deploy to Railway

  1. Push this repo to GitHub
  2. Connect to Railway
  3. Railway auto-detects the Dockerfile
  4. Set environment variables in Railway dashboard
  5. Deploy

Deploy to Render

  1. Push to GitHub
  2. Create a new Web Service on Render
  3. Select Docker environment
  4. Set environment variables
  5. Deploy

API Usage

Basic Screenshot

curl "http://localhost:3000/api/screenshot?url=https://example.com" -o screenshot.png

With Options

curl "http://localhost:3000/api/screenshot?url=https://github.com&width=1920&height=1080&format=jpeg&fullPage=true&quality=90" -o page.jpg

JSON Response (base64)

curl "http://localhost:3000/api/screenshot?url=https://example.com&response=json"

With API Key (paid tier)

curl -H "X-API-Key: sk_live_your_key" \
  "http://localhost:3000/api/screenshot?url=https://example.com"

Parameters

Parameter Type Default Description
url string - URL to capture (required)
width number 1280 Viewport width (320-3840)
height number 720 Viewport height (200-2160)
format string png png or jpeg
fullPage boolean false Capture full scrollable page
quality number 80 JPEG quality (1-100)
delay number 0 Wait after page load (ms)
response string image json for base64 response

Environment Variables

Variable Default Description
PORT 3000 Server port
NODE_ENV - production or development
API_KEYS - Comma-separated valid API keys
FREE_RATE_LIMIT 10 Free tier requests per window
FREE_RATE_WINDOW 60 Free tier window in seconds
PRO_RATE_LIMIT 1000 Pro tier requests per window
PRO_RATE_WINDOW 86400 Pro tier window in seconds
BROWSER_TIMEOUT 30000 Page load timeout in ms
CHROMIUM_PATH - Custom Chromium executable path
BROWSER_WS_ENDPOINT - Remote browser WebSocket URL

Security

  • SSRF protection: blocks private IPs, localhost, cloud metadata endpoints
  • DNS resolution validation to prevent DNS rebinding
  • Rate limiting per IP (free) or API key (paid)
  • Helmet security headers
  • Non-root Docker user
  • In-page request blocking for private addresses

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors