Allscreenshots
Sign inGet an API key
Blog

Guide

How to take website screenshots from the command line

Alex ChenUpdated 8 min read

Taking website screenshots from the command line unlocks automation possibilities that GUI tools can't match. Whether you're monitoring competitors, generating thumbnails, or building visual regression tests, CLI tools let you script the entire process.

This guide covers the main approaches: headless browsers, dedicated CLI tools, and screenshot APIs.

Why capture screenshots from the terminal?

Command-line screenshot tools solve problems that browser extensions and manual captures can't:

  1. Automation: Schedule captures with cron, integrate into CI/CD pipelines
  2. Batch processing: Capture hundreds of URLs from a file
  3. Consistency: Same viewport, timing, and settings every time
  4. Headless operation: Run on servers without displays
  5. Scripting: Chain with other tools, parse output, trigger workflows

If you're capturing more than a few screenshots per week, CLI tools will save you hours.

Using AllScreenshots CLI

The fastest way to capture website screenshots from the terminal is with a dedicated tool. AllScreenshots CLI handles browser rendering in the cloud, so you don't need to manage headless Chrome locally.

Installation

bash
# macOS/Linux with Homebrew brew tap allscreenshots/allscreenshots brew install allscreenshots # Or with Cargo (Rust) cargo install allscreenshots

Basic usage

Capture a screenshot and display it directly in your terminal:

bash
allscreenshots https://github.com

Save to a file instead:

bash
allscreenshots https://github.com -o github.png

Full page screenshots

Capture the entire scrollable page, not just the viewport:

bash
allscreenshots https://example.com --full-page -o fullpage.png

Device emulation

Test responsive designs by simulating different devices:

bash
# iPhone allscreenshots https://example.com --device "iPhone 14" -o mobile.png # Tablet allscreenshots https://example.com --device "iPad Pro 11" -o tablet.png # Desktop HD allscreenshots https://example.com --device "Desktop HD" -o desktop.png

List all available device presets:

bash
allscreenshots devices

Batch processing

Capture multiple URLs efficiently:

bash
# From a file (one URL per line) allscreenshots batch -f urls.txt -o ./screenshots/ # Multiple URLs inline allscreenshots batch https://github.com https://gitlab.com -o ./screenshots/

The batch command processes URLs concurrently, making it much faster than sequential captures.

Advanced options

OptionDescription
--format png/jpeg/webp/pdfOutput format
--quality 1-100Image quality (jpeg/webp)
--delay 1000Wait before capture (ms)
--dark-modeEnable dark mode
--block-adsBlock advertisements
--block-cookiesHide cookie banners
--wait-for ".selector"Wait for element to appear

Example combining options:

bash
allscreenshots https://example.com \ --full-page \ --dark-mode \ --block-cookies \ --format jpeg \ --quality 90 \ -o screenshot.jpg

Using Puppeteer from the command line

If you prefer running your own headless browser, Puppeteer can be wrapped in a simple Node.js script:

javascript
#!/usr/bin/env node // screenshot.js const puppeteer = require('puppeteer'); const url = process.argv[2]; const output = process.argv[3] || 'screenshot.png'; (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setViewport({ width: 1920, height: 1080 }); await page.goto(url, { waitUntil: 'networkidle0' }); await page.screenshot({ path: output, fullPage: true }); await browser.close(); console.log(`Saved: ${output}`); })();

Run it:

bash
node screenshot.js https://example.com output.png

Making it more flexible

A more complete script with options:

javascript
#!/usr/bin/env node const puppeteer = require('puppeteer'); const { program } = require('commander'); program .argument('<url>') .option('-o, --output <file>', 'output file', 'screenshot.png') .option('-w, --width <px>', 'viewport width', '1920') .option('-h, --height <px>', 'viewport height', '1080') .option('-f, --full-page', 'capture full page') .parse(); const url = program.args[0]; const opts = program.opts(); (async () => { const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] }); const page = await browser.newPage(); await page.setViewport({ width: parseInt(opts.width), height: parseInt(opts.height) }); await page.goto(url, { waitUntil: 'networkidle0' }); await page.screenshot({ path: opts.output, fullPage: opts.fullPage || false }); await browser.close(); console.log(`Saved: ${opts.output}`); })();

Using Playwright CLI

Playwright includes a built-in screenshot command:

bash
# Install Playwright npm install -g playwright # Capture screenshot npx playwright screenshot https://example.com screenshot.png # Full page npx playwright screenshot --full-page https://example.com fullpage.png # Specific viewport npx playwright screenshot --viewport-size=1280,720 https://example.com screenshot.png

Playwright's CLI is convenient for quick captures but lacks advanced features like ad blocking or cookie banner removal.

Using Chrome headless directly

Chrome itself can capture screenshots without additional tools:

bash
# macOS /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \ --headless \ --disable-gpu \ --screenshot=screenshot.png \ --window-size=1920,1080 \ https://example.com # Linux google-chrome \ --headless \ --disable-gpu \ --screenshot=screenshot.png \ --window-size=1920,1080 \ https://example.com

This approach works but has limitations:

  • No full-page capture
  • No waiting for dynamic content
  • Basic viewport control only
  • No device emulation

For anything beyond simple captures, use Puppeteer or a dedicated tool.

Using Firefox headless

Firefox also supports headless screenshots:

bash
firefox \ --headless \ --screenshot screenshot.png \ --window-size=1920,1080 \ https://example.com

Same limitations as Chrome's built-in approach apply.

Using curl with screenshot APIs

If you want to avoid local browser dependencies entirely, screenshot APIs work via HTTP:

bash
# Using AllScreenshots API directly curl --fail-with-body -X POST "https://api.allscreenshots.com/v1/screenshots" \ -H "X-API-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"url":"https://example.com","fullPage":true,"responseType":"binary"}' \ -o screenshot.png

This approach works from any environment that has curl, including minimal Docker containers and serverless functions.

Comparison of approaches

ApproachSetupSpeedFeaturesBest For
AllScreenshots CLIMinimalFastFullDaily use, automation
Puppeteer scriptModerateSlowCustomizableCustom workflows
Playwright CLIEasySlowBasicQuick one-off captures
Chrome headlessNoneSlowLimitedSimple captures
curl + APINoneFastFullServerless, containers

Automating with cron

Schedule regular captures with cron:

bash
# Edit crontab crontab -e # Capture every hour 0 * * * * allscreenshots https://example.com -o ~/screenshots/$(date +\%Y\%m\%d-\%H\%M).png --no-display # Capture daily at 9am 0 9 * * * allscreenshots https://competitor.com -o ~/monitoring/competitor-$(date +\%Y\%m\%d).png --no-display

Integrating with shell scripts

Combine screenshot captures with other tools:

bash
#!/bin/bash # monitor-sites.sh SITES=( "https://github.com" "https://gitlab.com" "https://bitbucket.org" ) OUTPUT_DIR=~/screenshots/$(date +%Y-%m-%d) mkdir -p "$OUTPUT_DIR" for site in "${SITES[@]}"; do filename=$(echo "$site" | sed 's|https://||' | sed 's|/|_|g') allscreenshots "$site" -o "$OUTPUT_DIR/${filename}.png" --no-display echo "Captured: $site" done echo "All screenshots saved to $OUTPUT_DIR"

Conclusion

Command-line screenshot tools transform what would be tedious manual work into automated workflows. For most users, a dedicated CLI tool like AllScreenshots offers the best balance of simplicity and features. You get cloud rendering, device emulation, and batch processing without managing headless browsers.

If you need complete control over the browser, Puppeteer scripts let you customize every aspect of the capture. For quick one-off screenshots, Playwright's CLI or Chrome's built-in headless mode work fine.

Start with simple captures, then add automation as your needs grow. A few lines of bash can replace hours of manual screenshot work.

Find out how easy it is to capture and share pixel-perfect screenshots at scale using Allscreenshots. Sign up for a free account and start integrating your first screenshot API call today.

Start with one request

Free plan: 100 screenshots. No credit card.

Get an API key
  • Full-page captures
  • Popups and repeated sticky bars removed
  • Markdown, JSON and PDF output
  • Crawl a site from one URL
  • Desktop, tablet and phone in one image
  • Works in n8n, Make and Zapier
  • MCP server for AI assistants