GitHunt
HA

harish-garg/cf-browser-render-cli-rust

A CLI written in rust for using cloudflare browser render APIs right in your Terminal

browserflare-cli

A Rust CLI for Cloudflare Browser Rendering APIs — crawl websites, capture screenshots, and generate PDFs from the command line.

Prefer a GUI App? Look at our desktop app - browserflare.xyz.

Features

  • Web Crawling — Single or batch URL crawling with configurable depth, scope, and output formats (HTML, Markdown, JSON)
  • AI Extraction — Extract structured JSON from pages using AI prompts and schemas
  • Screenshots — Capture full-page or element-targeted screenshots in PNG, JPEG, or WebP
  • PDF Generation — Render URLs or raw HTML to PDF with full page format and margin control
  • Job Management — List, monitor, cancel, search, compare, and delete crawl jobs
  • Interactive Mode — Menu-driven interface when run without arguments
  • Batch Processing — Process URL lists from files for all operations

Prerequisites

  • Rust toolchain (1.70+)
  • A Cloudflare account with Browser Rendering enabled
  • Cloudflare API token with appropriate permissions

Setup

  1. Clone the repository and navigate to the CLI directory:

    cd rust/cli
  2. Create a .env file with your Cloudflare credentials:

    CF_ACCOUNT_ID=your_account_id
    CF_API_TOKEN=your_api_token
    
  3. Build the project:

    cargo build --release

The compiled binary will be at target/release/browserflare.exe (Windows) or target/release/browserflare (Linux/macOS).

Usage

Interactive Mode

Run without arguments to launch the interactive menu:

browserflare

CLI Mode

browserflare <COMMAND> [OPTIONS]

Crawling

# Crawl a single URL
browserflare crawl --url https://browserflare.xyz --formats markdown --limit 50

# Crawl with depth and scope control
browserflare crawl --url https://browserflare.xyz --depth 3 --subdomains --external-links

# AI-powered JSON extraction
browserflare crawl --url https://browserflare.xyz --formats json --json-prompt "Extract product names and prices"

# Batch crawl from a file
browserflare batch --file urls.txt --formats html,markdown --limit 20

Key crawl options:

Option Description
--url <URL> URL to crawl
--limit <N> Max pages (default: 100)
--formats <FMT> Output formats: html, markdown, json
--depth <N> Max crawl depth
--no-render Disable JavaScript rendering
--subdomains Include subdomains
--external-links Follow external links
--include-patterns URL wildcard include filters
--exclude-patterns URL wildcard exclude filters
--reject-resources Block resource types (default: stylesheet, font, image, media)
--wait-selector CSS selector to wait for before extraction
--json-prompt AI extraction prompt
--json-schema Path to JSON schema for extraction
--label Job label for easy reference
--no-wait Don't wait for crawl completion

Screenshots

# Basic screenshot
browserflare screenshot --url https://browserflare.xyz

# Full-page JPEG with custom viewport
browserflare screenshot --url https://browserflare.xyz --full-page --format jpeg --quality 90 --width 1920 --height 1080

# Capture a specific element
browserflare screenshot --url https://browserflare.xyz --selector ".hero-section"

# Batch screenshots
browserflare screenshot-batch --file urls.txt --full-page --format png

Key screenshot options:

Option Description
--url <URL> URL to capture
--output <PATH> Custom output path
--full-page Capture full scrollable page
--format <FMT> png, jpeg, or webp (default: png)
--quality <0-100> JPEG/WebP quality
--width <N> Viewport width (default: 1280)
--height <N> Viewport height (default: 720)
--selector <SEL> CSS selector to capture
--device-scale <N> Device scale factor
--omit-background Transparent background

PDF Generation

# PDF from URL
browserflare pdf --url https://browserflare.xyz --format a4 --landscape

# PDF from raw HTML
browserflare pdf --html "<h1>Hello World</h1>" --print-background

# Batch PDFs
browserflare pdf-batch --file urls.txt --format letter --print-background

Key PDF options:

Option Description
--url <URL> URL to render
--html <HTML> Raw HTML string
--output <PATH> Custom output path
--format <FMT> Page format: letter, legal, a3, a4, a5, tabloid
--landscape Landscape orientation
--print-background Include background graphics
--scale <0.1-2.0> Rendering scale
--margin-top/bottom/left/right Page margins (e.g., 1cm, 0.5in)
--header-template HTML header template
--footer-template HTML footer template

Job Management

browserflare list                      # List all jobs
browserflare status                    # Check all pending jobs
browserflare status <JOB_ID>           # Check specific job
browserflare cancel <JOB_ID>           # Cancel a running crawl
browserflare stats <JOB_ID>            # View crawl statistics
browserflare search <JOB_ID> <QUERY>   # Search crawl results
browserflare diff <JOB_A> <JOB_B>      # Compare two crawls

Project Structure

src/
├── main.rs       # Entry point and async runtime setup
├── cli.rs        # CLI argument definitions (clap)
├── handlers.rs   # Command handler implementations
└── prompts.rs    # Interactive menu and prompt functions

License

MIT

harish-garg/cf-browser-render-cli-rust | GitHunt