SkillsApr 7, 2026·2 min read

Stagehand — AI-Powered Browser Automation SDK

TypeScript SDK that lets you automate browsers using natural language and visual understanding. AI sees the page like a human does. Built on Playwright. 10,000+ GitHub stars.

TL;DR
Stagehand automates browsers using natural language instructions and visual page understanding, built on Playwright.
§01

What it is

Stagehand is a TypeScript SDK that lets you automate browsers using natural language and visual understanding. Instead of writing CSS selectors or XPath queries, you describe what you want in plain English and Stagehand's AI figures out how to interact with the page. It is built on Playwright, so you get the reliability of a mature browser automation framework with AI-powered element selection.

Stagehand is designed for developers building web scrapers, test automation, or browser-based workflows who want to reduce the fragility of selector-based automation.

§02

How it saves time or tokens

Traditional browser automation breaks when websites change their HTML structure, CSS classes, or DOM hierarchy. Stagehand's AI-based element selection is resilient to these changes because it understands the visual layout and semantic meaning of page elements. A test that says 'click the login button' works regardless of whether the button's class name changes. This reduces maintenance time and the cost of keeping automation scripts up to date.

§03

How to use

  1. Install Stagehand:
npm install @browserbasehq/stagehand
  1. Create an automation script:
import { Stagehand } from '@browserbasehq/stagehand';

const stagehand = new Stagehand({ env: 'LOCAL' });
await stagehand.init();
await stagehand.page.goto('https://news.ycombinator.com');

// AI-powered actions
await stagehand.act({ action: 'click the first article link' });
const title = await stagehand.extract({
  instruction: 'extract the article title',
  schema: { type: 'object', properties: { title: { type: 'string' } } },
});
console.log(title);
  1. Run your script with Node.js or integrate it into your test suite.
§04

Example

A web scraping workflow that extracts product data:

import { Stagehand } from '@browserbasehq/stagehand';

const stagehand = new Stagehand({ env: 'LOCAL' });
await stagehand.init();
await stagehand.page.goto('https://example-store.com/products');

const products = await stagehand.extract({
  instruction: 'extract all product names, prices, and ratings from the page',
  schema: {
    type: 'array',
    items: {
      type: 'object',
      properties: {
        name: { type: 'string' },
        price: { type: 'string' },
        rating: { type: 'number' },
      },
    },
  },
});

console.log(JSON.stringify(products, null, 2));
await stagehand.close();
§05

Related on TokRepo

§06

Common pitfalls

  • Using Stagehand for tasks where simple selectors work fine. AI-based selection adds latency and API costs. Use traditional Playwright selectors for stable, well-known page structures and Stagehand for dynamic or frequently changing pages.
  • Not handling authentication cookies. For pages behind login, handle authentication in a traditional Playwright step before using Stagehand's AI features.
  • Expecting 100% accuracy on complex pages. AI-based element selection is probabilistic. Add assertions and error handling to catch cases where the AI selects the wrong element.

Frequently Asked Questions

How does Stagehand select elements without selectors?+

Stagehand uses an AI model that takes a screenshot and the page's accessibility tree as input. It identifies elements by their visual appearance and semantic meaning rather than CSS selectors. This makes it resilient to DOM structure changes.

Does Stagehand work with all websites?+

Stagehand works with any website that Playwright can render. It supports modern JavaScript-heavy single-page applications, server-rendered pages, and static sites. Some sites with aggressive bot detection may require additional configuration.

Can I mix Stagehand AI actions with regular Playwright commands?+

Yes. Stagehand extends Playwright, so you have full access to Playwright's API alongside Stagehand's AI actions. Use Playwright for navigation and known interactions, and Stagehand's act/extract for dynamic elements.

Which AI model does Stagehand use?+

Stagehand supports multiple AI providers. By default, it uses the model configured in your environment. You can specify the model provider and API key in the Stagehand constructor options.

Is Stagehand suitable for production scraping?+

Stagehand can be used in production, but consider the AI API costs per action. For high-volume scraping, use Stagehand to generate selectors once, then switch to pure Playwright for production runs to reduce costs.

Citations (3)
🙏

Source & Thanks

Created by Browserbase. Licensed under MIT.

stagehand — stars 10,000+

Thanks for making browser automation speak human.

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets