AI 驱动的浏览器自动化框架
阅读文档
如果你在寻找 Python 实现,可以访问 这里
Stagehand 是一个浏览器自动化框架,用于通过自然语言和代码来控制网络浏览器。通过将 AI 的强大功能与代码的精确性相结合,Stagehand 使 Web 自动化变得灵活、可维护且真正可靠。
大多数现有的浏览器自动化工具要么要求你在 Selenium、Playwright 或 Puppeteer 等框架中编写底层代码,要么使用在生产环境中可能不可预测的高级代理。通过让开发人员选择何时编写代码、何时使用自然语言(并弥合两者之间的差距),Stagehand 是生产环境中浏览器自动化的自然选择。
只需一行代码即可开始使用 Stagehand,或查看我们的 快速入门指南 了解更多信息:
npx create-browser-app
以下是如何使用 Stagehand 构建一个示例浏览器自动化:
// Stagehand 的 CDP 引擎提供了一个为自动化构建的、优化的浏览器底层接口
const page = stagehand.context.pages()[0];
await page.goto("https://github.com/browserbase");
// 使用 act() 执行单个操作
await stagehand.act("click on the stagehand repo");
// 使用 agent() 处理多步骤任务
const agent = stagehand.agent();
await agent.execute("Get to the latest PR");
// 使用 extract() 从页面提取结构化数据
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"),
}),
);
访问 docs.stagehand.dev 查看完整文档。
git clone https://github.com/browserbase/stagehand.git
cd stagehand
pnpm install
pnpm run build
pnpm run example # 运行 ./examples/example.ts 中的空白脚本
当您拥有 LLM 提供商的 API 密钥和 Browserbase 凭证时,Stagehand 的效果最佳。要将这些添加到您的项目中,请运行:
cp .env.example .env
nano .env # 编辑 .env 文件以添加 API 密钥
您可以使用 gitpkg 直接从 GitHub 分支安装和构建 Stagehand。
在您项目的 package.json 中设置:
"@browserbasehq/stagehand": "https://gitpkg.now.sh/browserbase/stagehand/packages/core?<branchName>",
[!NOTE]
我们非常重视对 Stagehand 的贡献!如有问题或需要支持,请加入我们的 Discord 社区。
总体而言,我们按优先级顺序专注于提高可靠性、可扩展性、速度和降低成本。如果您有兴趣贡献,修复错误和进行小的改进是最好的入门方式。对于更复杂的特性,我们强烈建议在开始之前,通过我们的 Discord 社区 联系 Miguel Gonzalez 或 Paul Klein,以确保您的贡献符合我们的目标。
我们要感谢以下人员对 Stagehand 做出的重大贡献:
- Paul Klein
- Sean McGuire
- Miguel Gonzalez
- Sameel Arif
- Thomas Katwan
- Filip Michalsky
- Anirudh Kamath
- Jeremy Press
- Navid Pour
基于 MIT 许可证授权。
版权所有 2025 Browserbase, Inc.