Skip to main content
Install Stagehand in your current app with the TypeScript SDK.
We recommend using the Node.js runtime environment to run Stagehand scripts.Bun is now supported as long as you do not integrate Stagehand with Playwright. Playwright is not compatible with Bun.
  • TypeScript
  • Python

Install dependencies

npm install @browserbasehq/stagehand
If you plan to run locally, you need to have Chrome installed on your machine. For cloud browser sessions, skip this.

Configure environment

Set environment variables (or a .env via your framework):
OPENAI_API_KEY=your_api_key
BROWSERBASE_API_KEY=your_api_key
BROWSERBASE_PROJECT_ID=your_project_id

Use in your codebase

Add Stagehand where you need browser automation.
import "dotenv/config";
import { Stagehand } from "@browserbasehq/stagehand";
import { z } from "zod/v3";

async function main() {
  const stagehand = new Stagehand({
    env: "BROWSERBASE"
  });

  await stagehand.init();
  const page = stagehand.context.pages()[0];

  await page.goto("https://example.com");

  // Act on the page
  await stagehand.act("Click the sign in button");

  // Extract structured data
  const title = await stagehand.extract("extract the page title", z.string());

  console.log(title);
  await stagehand.close();
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

Next steps