A service for capturing website screenshots with various options, built with Node.js, Express, and Playwright.
- Device emulation (desktop, tablet, phone)
- Custom dimensions and full-page screenshots
- Multiple formats (PNG, JPEG, GIF)
- Cache management with TTL
- Element interaction (click, hide)
- Crop functionality
- Custom request headers
Pre-built Docker images are available on GitHub Container Registry:
# Pull the latest version
docker pull ghcr.io/vlazic/playwright-screenshot-api:latest
# Run the container
docker run -p 3000:3000 ghcr.io/vlazic/playwright-screenshot-api:latest
Images are available for both x86_64/amd64 and ARM64/aarch64 architectures. Docker will automatically pull the correct image for your platform.
GET /health
Returns server status and version information.
Available options:
device
: desktop, tablet, phonewidth
: custom widthheight
: custom heightformat
: png, jpg, gifquality
: 0-100 (for jpg)scale
: for high-DPI (1-5)fullPage
: capture full pagedelay
: wait before capture (0-10000ms)fresh
: bypass cachereturnUrl
: return cache URL instead of imageclickSelectors
: click elements before capturehideSelectors
: hide elementsselector
: capture specific elementcrop
: crop screenshot
POST /screenshot
Content-Type: application/json
{
"url": "https://vlazic.com",
"device": "desktop",
"width": 1024,
"height": 768,
"format": "png",
"quality": 80,
"scale": 2,
"fullPage": true,
"delay": 1000,
"fresh": false,
"returnUrl": false,
"clickSelectors": ["#menu"],
"hideSelectors": [".ads"],
"selector": ".content",
"crop": {
"x": 0,
"y": 0,
"width": 100,
"height": 100
}
}
npm install
Start the server:
npm start
Development mode with auto-reload:
npm run dev
Build and run locally with Docker Compose:
# Development mode with hot-reload
npm run docker:dev
# Production mode
npm run docker:prod
Build manually:
docker build -t playwright-screenshot-api .
docker run -p 3000:3000 playwright-screenshot-api
# Run API tests
npm run test:api
# Watch mode for development
npm run test:api:watch
# Generate coverage report
npm run test:api:coverage
# Visual regression tests
npm run test:manual:visual
# Cache functionality tests
npm run test:manual:cache
tests/api/health.test.js
: Health endpoint teststests/api/screenshot.test.js
: Screenshot endpoint tests covering:- Basic functionality
- Device emulation
- Format and quality options
- Dimensions and cropping
- Element interaction
- Caching behavior
- Error handling
Images are automatically built and published to GitHub Container Registry on:
- Push to master branch
- New version tags
- Pull requests (build only, not published)
The build process creates multi-architecture images supporting:
- Linux x86_64/amd64
- Linux ARM64/aarch64
MIT