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.
Agent 可直接安装
这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install fd07b08f-5d31-404c-bd80-6e0587a6b712 --target codex先 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.
常见问题
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.
引用来源 (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
来源与感谢
Created by Browserbase. Licensed under MIT.
stagehand — stars 10,000+
讨论
相关资产
Browser-Use Web UI — Visual AI Browser Automation
Gradio-based web interface for Browser-Use AI agent. Automate web browsing with visual feedback, persistent sessions, and HD recording. Supports 6+ LLM providers. 15,800+ stars, MIT.
Browser Use — AI Browser Automation
Open-source Python library for AI-driven browser automation. Works with Claude, GPT, and Gemini to fill forms, scrape data, and navigate websites.
ScrapeGraphAI — AI-Powered Web Scraping
Python scraping library powered by LLMs. Describe what you want to extract in natural language, get structured data back. Handles dynamic pages. 23K+ stars.
Docker Selenium Grid — Containerized Browser Testing at Scale
Docker Selenium provides pre-built container images to run Selenium Grid with Chrome, Firefox, and Edge, enabling scalable browser automation in CI/CD pipelines.