Skip to main content

What is Stagehand?

Stagehand is a browser automation framework used to control web browsers with natural language and code. By combining the power of AI with the precision of code, Stagehand makes web automation flexible, maintainable, and actually reliable.

Quickstart Guide

Get started with Stagehand in minutes

Installation

Detailed installation instructions

API Reference

Explore the complete API documentation

Examples

View real-world automation examples

Why Stagehand?

Most existing browser automation tools either require you to write low-level code in a framework like Selenium, Playwright, or Puppeteer, or use high-level agents that can be unpredictable in production. By letting developers choose what to write in code vs. natural language (and bridging the gap between the two) Stagehand is the natural choice for browser automations in production.

Flexible Control

Choose when to write code vs. natural language: use AI when you want to navigate unfamiliar pages, and use code when you know exactly what you want to do.

AI-Driven to Repeatable

Preview AI actions before running them, and easily cache repeatable actions to save time and tokens.

Write Once, Run Forever

Auto-caching combined with self-healing remembers previous actions, runs without LLM inference, and knows when to involve AI whenever the website changes.

Key Features

Natural Language Actions

Use act() to execute browser actions with simple commands:
await stagehand.act("click on the stagehand repo");

Structured Data Extraction

Extract data from web pages with type-safe schemas:
const { author, title } = await stagehand.extract(
  "extract the author and title of the PR",
  z.object({
    author: z.string().describe("The username of the PR author"),
    title: z.string().describe("The title of the PR"),
  }),
);

Multi-Step Agents

Create agents that can execute complex, multi-step tasks:
const agent = stagehand.agent();
await agent.execute("Get to the latest PR");

Browser Control

Access Stagehand’s optimized CDP engine for low-level browser control:
const page = stagehand.context.pages()[0];
await page.goto("https://github.com/browserbase");

Example Automation

Here’s a complete example that navigates to GitHub, clicks on a repository, and extracts PR information:
import { Stagehand } from "@browserbasehq/stagehand";
import { z } from "zod";

const stagehand = new Stagehand({
  env: "BROWSERBASE",
  apiKey: process.env.BROWSERBASE_API_KEY,
  projectId: process.env.BROWSERBASE_PROJECT_ID,
});

await stagehand.init();

// Navigate to GitHub
const page = stagehand.context.pages()[0];
await page.goto("https://github.com/browserbase");

// Use act() to execute individual actions
await stagehand.act("click on the stagehand repo");

// Use agent() for multi-step tasks
const agent = stagehand.agent();
await agent.execute("Get to the latest PR");

// Use extract() to get structured data
const { author, title } = await stagehand.extract(
  "extract the author and title of the PR",
  z.object({
    author: z.string().describe("The username of the PR author"),
    title: z.string().describe("The title of the PR"),
  }),
);

console.log(`PR by ${author}: ${title}`);

await stagehand.close();

Core Methods

Stagehand provides four core methods for browser automation:

act()

Execute individual browser actions with natural language

extract()

Extract structured data from web pages with type-safe schemas

observe()

Identify possible actions on a page without executing them

agent()

Create autonomous agents for multi-step automation tasks

Browser Environments

Stagehand supports multiple browser environments:
  • BROWSERBASE - Cloud-based browser infrastructure (recommended for production)
  • LOCAL - Run on your local machine for development
  • Compatible with Playwright, Puppeteer, and Patchright

Next Steps

1

Get Started

Follow the Quickstart Guide to create your first automation in minutes
2

Install Stagehand

See Installation for detailed setup instructions
3

Learn Core Concepts

Understand how Stagehand works under the hood
4

Explore Examples

Browse real-world examples to learn best practices
Need help? Join our Discord community or check out the GitHub repository for support.

Build docs developers (and LLMs) love