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.
Installation agent prête
Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.
npx -y tokrepo@latest install fd07b08f-5d31-404c-bd80-6e0587a6b712 --target codexÀ exécuter après confirmation du plan en dry-run.
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.
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.
How to use
- Install Stagehand:
npm install @browserbasehq/stagehand
- 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);
- Run your script with Node.js or integrate it into your test suite.
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();
Related on TokRepo
- Browser automation tools — Browse AI-powered browser tools
- Web scraping tools — Explore web data extraction tools
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.
Questions fréquentes
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.
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.
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.
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.
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.
Sources citées (3)
- Stagehand GitHub— Stagehand is a TypeScript SDK for AI browser automation
- Playwright Documentation— Built on Playwright browser automation framework
- Browserbase— Browserbase cloud browser infrastructure
En lien sur TokRepo
Fil de discussion
Actifs similaires
Stagehand — AI Browser Automation Framework
Three AI primitives — act(), extract(), observe() — to automate any website with natural language. By Browserbase. 21K+ stars.
Browserbase — Cloud Browser Infra for AI Agents
Browserbase runs managed cloud Chromium for AI agents. Stagehand, Playwright, Puppeteer compatible. Scales to 1000s of parallel sessions with replay.
Jackett — Unified Torrent Indexer API for Media Automation
A proxy server that translates queries from media automation apps like Sonarr and Radarr into site-specific requests for torrent indexers, providing a single API interface.
Browserbase MCP — Cloud Browser Automation Tools
Browserbase MCP server exposes automation tools (navigate, act, observe, extract) backed by Browserbase + Stagehand, letting agents operate real web pages.