WebShot
A fast command-line tool for taking website screenshots, built in Rust.
Features
- Take full-page or element-specific screenshots
- Generate PDFs from web pages
- Execute JavaScript before capturing
- Batch processing with YAML configs
- Support for PNG, JPEG, WebP, and PDF formats
- Custom viewports and mobile emulation
- Wait for elements or timeouts
- Extract text content from pages
- Multiple comparison algorithms (pixel-diff, SSIM, MSE, PSNR)
- Generate difference images highlighting changes
- Visual regression testing support
- Configurable similarity thresholds
- Works on Windows, macOS, and Linux
Installation
From Source
You'll need Chrome or Chromium installed. The tool will find it automatically.
Quick Start
# Basic screenshot
# Custom size and output
# Screenshot just the header
# Generate a PDF
# Screenshot in WebP format
# Extract text content
Usage
Basic Options
-o, --output- Output file path-w, --width- Viewport width (default: 1280)-h, --height- Viewport height (default: 800)-s, --selector- CSS selector for element screenshots-j, --javascript- JavaScript to run before screenshot--wait-for- Wait for element to appear-t, --timeout- Timeout in seconds (default: 30)--retina- Enable high-DPI mode-q, --quality- JPEG/WebP quality 1-100-v, --verbose- Verbose logging
Subcommands
screenshot
Basic screenshot with full options:
pdf
Generate PDF from webpage:
multi
Process multiple screenshots from YAML config:
text
Extract text content:
compare
Compare two images for differences:
# Basic comparison
# Use different algorithm with threshold
# Generate difference image
# Output results as JSON
# Ignore anti-aliasing differences
Configuration Files
For batch processing, create a YAML file:
# Simple config
screenshots:
- url: "https://example.com"
output: "example.png"
- url: "https://github.com"
output: "github.png"
width: 1920
height: 1080
Advanced config with defaults:
defaults:
width: 1280
height: 800
timeout: 30
output_dir: "screenshots"
screenshots:
- url: "https://github.com"
output: "github-header.png"
selector: ".Header"
- url: "https://example.com"
output: "interactive.png"
javascript: "document.querySelector('button').click();"
- url: "https://spa-app.com"
output: "spa-loaded.png"
wait_for: ".content"
timeout: 15
Configuration Options
url- Target URL (required)output- Output file path (required)width,height- Viewport dimensionsselector- CSS selector for element screenshotsjavascript- JavaScript code to executewait_for- CSS selector to wait fortimeout- Timeout in secondsretina- Enable retina modequality- JPEG/WebP quality 1-100wait- Wait time before screenshotuser_agent- Custom user agentheaders- Custom HTTP headerscookies- Cookies to setauth- Basic authentication (username/password)
Examples
Mobile Screenshots
# iPhone viewport
# iPad viewport
JavaScript Execution
# Click elements and modify page
Custom Chrome Setup
# Use custom Chrome path
# Add Chrome flags
Troubleshooting
Chrome not found: Use --chrome-path to specify location manually
Element not found: Check CSS selector syntax, use --wait-for for dynamic content
Timeouts: Increase with -t flag, check network connection
JavaScript errors: Use -v for verbose logging
Development
# Build
# Run tests
# Integration tests (needs Chrome)
License
MIT License - see LICENSE file for details.
Built with headless_chrome and clap.