Stagehand
An SDK by Browserbase for building browser-based AI agents. Automate web interactions using natural language, actions, and observation APIs.
Introduction
Stagehand is an open-source SDK developed by Browserbase for building browser-based AI agents. It provides a clean, high-level API for instructing AI agents to navigate, interact with, and extract data from web pages. With over 23,500 GitHub stars and 1,393 commits, it is one of the most popular browser automation frameworks in the AI ecosystem.
The source code is available on GitHub at github.com/browserbase/stagehand. Stagehand is designed to work with modern AI models, including GPT-5 and Claude, and integrates with the Browserbase cloud platform for scalable browser orchestration.
Key Features
- Natural Language Actions - Instruct agents with plain English like "click the login button" or "fill in the search form."
- Observation API - AI-powered extraction of structured data from web pages using natural language queries.
- Action-Aware Snapshots - Page snapshots optimized for AI models, showing only interactive elements with unique identifiers.
- Multi-Model Support - Compatible with OpenAI, Anthropic, and other LLMs for flexible agent design.
- Headless & Headful - Run browsers in headless mode for automation or visible mode for debugging.
- Session Management - Built-in handling of browser contexts, cookies, and authentication state.
Core APIs
| API | Purpose | Example |
|---|---|---|
page.act() | Perform an action on the page | page.act("click the search button") |
page.observe() | Extract structured data from the page | page.observe("list all products with prices") |
page.extract() | Extract specific data with a schema | page.extract({name: "string", price: "number"}) |
page.navigate() | Navigate to a URL | page.navigate("https://example.com") |
AI Actions and Observation
Stagehand's AI-powered action system translates natural language instructions into precise browser interactions. When you call page.act(), Stagehand takes a snapshot of the page, sends it with your instruction to an AI model, and the model determines which element to interact with and what action to perform.
The Observation API (page.observe()) enables agents to extract structured information from web pages by describing what they need in natural language. Stagehand captures the page state, analyzes it with AI, and returns structured data — making it ideal for web scraping, research, and data collection workflows.
Installation
npm install @browserbasehq/stagehand
Stagehand requires Node.js 18+ and a Playwright-compatible browser. It can be used standalone or with the Browserbase cloud platform for remote browser orchestration.
Usage
Basic example:
import { Stagehand } from "@browserbasehq/stagehand";
const stagehand = new Stagehand();
await stagehand.init();
await stagehand.page.navigate("https://example.com");
const title = await stagehand.page.extract({ title: "string" });
console.log("Page title:", title);
await stagehand.close();