Smart Fetch Scraper with Browser Fallback

Scrape webpages using the fastest method available: Fetch API first, full browser session as fallback for JS-rendered pages.

Smart Fetch Scraper with Browser Fallback demo
Copy prompt to run with your AI agent

Get started with the Smart Fetch Scraper

Scrape web pages using the fastest and most cost-effective method available. The Browserbase Fetch API handles most pages instantly, retrieving content in milliseconds without spinning up a browser session or using AI credits. For the rare cases where JavaScript rendering is required, the template gracefully falls back to a full Stagehand browser session with AI-powered extract(). Perfect for cost-optimized scraping pipelines, speed-sensitive workflows, and hybrid data extraction scenarios.

Steps

  1. Send a POST request to the Browserbase Fetch API (/v1/fetch) with the target URL

  2. Check response content length and text density to determine if the page is server-rendered

  3. If content is sufficient, parse the HTML directly for fast, zero-cost extraction

  4. If content is insufficient (JS-rendered pages), fall back to a Stagehand browser session

  5. Use Stagehand's AI-powered extract() with Zod schemas to pull structured data from complex pages