Three Core Methods
act() — Do Something
await stagehand.act({ action: "click the Sign In button" });
await stagehand.act({ action: "fill in the email field with test@example.com" });
await stagehand.act({ action: "select Monthly from the billing dropdown" });
await stagehand.act({ action: "scroll down to the pricing section" });extract() — Get Data
const data = await stagehand.extract({
instruction: "extract all product names and prices",
schema: z.object({
products: z.array(z.object({
name: z.string(),
price: z.number(),
})),
}),
});observe() — Understand the Page
const elements = await stagehand.observe({
instruction: "find all interactive elements on this page",
});
// Returns: buttons, links, inputs with their descriptionsWhy Stagehand Over Playwright
| Playwright | Stagehand |
|---|---|
page.click('[data-testid="login"]') |
act("click the Login button") |
| Breaks when selectors change | Works even after UI redesign |
| Need to inspect DOM manually | AI sees the page visually |
| Complex selector chains | Natural language instructions |
Best of Both Worlds
Stagehand is built on Playwright — you can mix both:
// Use Stagehand for AI-powered steps
await stagehand.act({ action: "navigate to the settings page" });
// Drop down to Playwright for precise control
await stagehand.page.waitForSelector("#settings-form");
const value = await stagehand.page.inputValue("#email");Structured Extraction with Zod
import { z } from "zod";
const articles = await stagehand.extract({
instruction: "extract all news articles from this page",
schema: z.object({
articles: z.array(z.object({
title: z.string(),
author: z.string(),
date: z.string(),
summary: z.string(),
})),
}),
});
// Fully typed: articles.articles[0].titleUse Cases
| Scenario | Example |
|---|---|
| E2E testing | "Login, add item to cart, checkout" |
| Web scraping | "Extract all job listings from this page" |
| Form filling | "Fill out the application form with this data" |
| Monitoring | "Check if the status page shows all green" |
| Screenshots | "Navigate to dashboard and take a screenshot" |
Key Stats
- 10,000+ GitHub stars
- Built on Playwright
- 3 methods: act, extract, observe
- Zod schema for typed extraction
- Visual AI understanding
FAQ
Q: What is Stagehand? A: A TypeScript SDK for browser automation using natural language — AI sees the page visually and performs actions without CSS selectors.
Q: Is Stagehand free? A: Yes, open-source under MIT. Uses your own LLM API key for vision.
Q: Does Stagehand replace Playwright? A: No, it is built on Playwright and adds AI-powered natural language control. You can use both together.