Welcome to the comprehensive documentation for Webfn, the agent-oriented CLI for browser-backed search, fetch, and crawl workflows.
Webfn is designed from the ground up to be the ultimate companion for AI agents and automation scripts that need to interface with the modern web. It abstracts away the complexities of headless browsers, search engine scraping, and HTML-to-Markdown conversion.
Webfn uses a tiered configuration resolution system. Options are applied in the following order of precedence:
- CLI Flags:
--output-dir <dir> - Environment Variables:
WEBFN_OUTPUT_DIR - Config File:
webfn.config.json - Built-in Defaults
You can create a webfn.config.json file in your project root to set default behaviors.
{
"outputDir": "agent-data",
"provider": "google | duckduckgo",
"mdEngine": "defuddle | turndown",
"timeout": 30000,
"delay": 1200,
"results": 5,
"waitUntil": "networkidle2 | domcontentloaded",
"engine": "chrome | lightpanda | cloudflare",
"cloudflareAccountId": "your_cloudflare_account_id_here",
"cloudflareApiToken": "your_cloudflare_api_token_here"
}outputDir: Directory where fetched files, screenshots, and metadata will be saved.provider: Search engine to use for queries.mdEngine: Markdown parser for converting HTML to Markdown.timeout: Maximum time in milliseconds to wait for page navigation and fetching.delay: Time in milliseconds to wait AFTER the page has loaded before capturing content/screenshot.results: Default number of search results to fetch and collect.waitUntil: Puppeteer wait condition for page loads.engine: Browser execution engine. 'chrome' (local headless), 'lightpanda' (local fast engine), 'cloudflare' (remote serverless edge rendering).cloudflareAccountId: Your Cloudflare Account ID. Required ONLY if engine is set to 'cloudflare'. (It is safer to set this in your.envfile).cloudflareApiToken: Your Cloudflare API Token. Required ONLY if engine is set to 'cloudflare'. (It is safer to set this in your.envfile).
Searches the web using a specific provider and returns structured data.
webfn search "openai latest models" --provider duckduckgoSearches the web and then immediately fetches the HTML/Markdown content for the top X results.
webfn collect "how to learn rust" --results 3Fetches a specific URL and extracts readable Markdown.
webfn fetch https://example.com --html --metaTakes a screenshot of a website. Supports full-page scrolling and Cloudflare edge rendering.
webfn screenshot https://example.com --full --delay 2000Crawls an entire website starting from a given URL or Sitemap.
webfn crawl https://example.com --depth 2 --max-pages 50 --fetch-pagesChecks your local environment to ensure Chrome and other dependencies are correctly installed.
webfn doctorWebfn supports multiple execution backends to optimize for speed, stealth, or cost.
- Lightpanda (
--engine lightpanda): Ultra-fast, lightweight headless browser optimized for data extraction. Uses lower memory. - Chrome (
--engine chrome): Uses your local Chrome/Chromium installation. Best for complex SPAs and full-page rendering. - Cloudflare (
--engine cloudflare): Uses Cloudflare's Browser Rendering REST API. Runs entirely on Cloudflare's edge network. Bypasses many basic bot protections. Does not support--fullscreenshots.
Converting complex DOM structures to readable Markdown is challenging. Webfn provides two parsers:
- Defuddle (
--md-engine defuddle): A custom-built, highly accurate extractor designed to strip noise (navbars, footers) and focus purely on the article content. This is the default. - Turndown (
--md-engine turndown): A standard HTML-to-Markdown library. Best for converting the entire page literally.
Webfn is uniquely built for AI agents.
If Webfn detects that its output is being piped to another program (or read by a child process), it automatically silences all progress bars, spinners, and interactive UI, and outputs a single, strictly formatted JSON object.
# Handled by a terminal user (rich UI)
webfn fetch https://example.com
# Handled by an AI Agent or script (JSON output)
webfn fetch https://example.com | jq .page.markdownYou can force JSON output in a terminal using the --json flag.