Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@browserbasehq/stagehand

browserbase1.3mMIT2.3.0TypeScript support: included

An AI web browsing framework focused on simplicity and extensibility.

readme

The AI Browser Automation Framework
Read the Docs

<picture> <source media="(prefers-color-scheme: dark)" srcset="media/dark_license.svg" /> MIT License </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="media/dark_slack.svg" /> Slack Community </picture>

browserbase%2Fstagehand | Trendshift

Why Stagehand?

Most existing browser automation tools either require you to write low-level code in a framework like Selenium, Playwright, or Puppeteer, or use high-level agents that can be unpredictable in production. By letting developers choose what to write in code vs. natural language, Stagehand is the natural choice for browser automations in production.

  1. Choose when to write code vs. natural language: use AI when you want to navigate unfamiliar pages, and use code (Playwright) when you know exactly what you want to do.

  2. Preview and cache actions: Stagehand lets you preview AI actions before running them, and also helps you easily cache repeatable actions to save time and tokens.

  3. Computer use models with one line of code: Stagehand lets you integrate SOTA computer use models from OpenAI and Anthropic into the browser with one line of code.

Example

Here's how to build a sample browser automation with Stagehand:

See Stagehand in Action
// Use Playwright functions on the page object
const page = stagehand.page;
await page.goto("https://github.com/browserbase");

// Use act() to execute individual actions
await page.act("click on the stagehand repo");

// Use Computer Use agents for larger actions
const agent = stagehand.agent({
    provider: "openai",
    model: "computer-use-preview",
});
await agent.execute("Get to the latest PR");

// Use extract() to read data from the page
const { author, title } = await page.extract({
  instruction: "extract the author and title of the PR",
  schema: z.object({
    author: z.string().describe("The username of the PR author"),
    title: z.string().describe("The title of the PR"),
  }),
});

Documentation

Visit docs.stagehand.dev to view the full documentation.

Getting Started

Start with Stagehand with one line of code, or check out our Quickstart Guide for more information:

npx create-browser-app

Build and Run from Source

git clone https://github.com/browserbase/stagehand.git
cd stagehand
pnpm install
pnpm playwright install
pnpm run build
pnpm run example # run the blank script at ./examples/example.ts
pnpm run example 2048 # run the 2048 example at ./examples/2048.ts

Stagehand is best when you have an API key for an LLM provider and Browserbase credentials. To add these to your project, run:

cp .env.example .env
nano .env # Edit the .env file to add API keys

Contributing

[!NOTE]
We highly value contributions to Stagehand! For questions or support, please join our Slack community.

At a high level, we're focused on improving reliability, speed, and cost in that order of priority. If you're interested in contributing, we strongly recommend reaching out to Anirudh Kamath or Paul Klein in our Slack community before starting to ensure that your contribution aligns with our goals.

For more information, please see our Contributing Guide.

Acknowledgements

This project heavily relies on Playwright as a resilient backbone to automate the web. It also would not be possible without the awesome techniques and discoveries made by tarsier, gemini-zod, and fuji-web.

We'd like to thank the following people for their major contributions to Stagehand:

License

Licensed under the MIT License.

Copyright 2025 Browserbase, Inc.

changelog

@browserbasehq/stagehand

2.3.1

Patch Changes

2.3.0

Minor Changes

Patch Changes

2.2.1

Patch Changes

2.2.0

Minor Changes

Patch Changes

2.1.0

Minor Changes

Patch Changes

2.0.0

Major Changes

  • #591 e234a0f Thanks @miguelg719! - Announcing Stagehand 2.0! 🎉

    We're thrilled to announce the release of Stagehand 2.0, bringing significant improvements to make browser automation more powerful, faster, and easier to use than ever before.

    🚀 New Features

    • Introducing stagehand.agent: A powerful new way to integrate SOTA Computer use models or Browserbase's Open Operator into Stagehand with one line of code! Perfect for multi-step workflows and complex interactions. Learn more
    • Lightning-fast act and extract: Major performance improvements to make your automations run significantly faster.
    • Enhanced Logging: Better visibility into what's happening during automation with improved logging and debugging capabilities.
    • Comprehensive Documentation: A completely revamped documentation site with better examples, guides, and best practices.
    • Improved Error Handling: More descriptive errors and better error recovery to help you debug issues faster.

    🛠️ Developer Experience

    • Better TypeScript Support: Enhanced type definitions and better IDE integration
    • Better Error Messages: Clearer, more actionable error messages to help you debug faster
    • Improved Caching: More reliable action caching for better performance

    We're excited to see what you build with Stagehand 2.0! For questions or support, join our Slack community.

    For more details, check out our documentation.

Minor Changes

  • #588 ba9efc5 Thanks @sameelarif! - Added support for offloading agent tasks to the API.

  • #600 11e015d Thanks @sameelarif! - Added a stagehand.history array which stores an array of act, extract, observe, and goto calls made. Since this history array is stored on the StagehandPage level, it will capture methods even if indirectly called by an agent.

  • #601 1d22604 Thanks @seanmcguire12! - add custom error classes

  • #599 75d8fb3 Thanks @miguelg719! - cleaner logging with pino

  • #609 c92295d Thanks @kamath! - Removed deprecated fields and methods from Stagehand constructor and added cdpUrl to localBrowserLaunchOptions for custom CDP URLs support.

  • #571 73d6736 Thanks @miguelg719! - You can now use Computer Using Agents (CUA) natively in Stagehand for both Anthropic and OpenAI models! This unlocks a brand new frontier of applications for Stagehand users 🤘

  • #619 7b0b996 Thanks @sameelarif! - add disablePino flag to stagehand constructor params

  • #620 566e587 Thanks @kamath! - You can now pass in an OpenAI instance as an llmClient to the Stagehand constructor! This allows you to use Stagehand with any OpenAI-compatible model, like Ollama, Gemini, etc., as well as OpenAI wrappers like Braintrust.

  • #586 c57dc19 Thanks @sameelarif! - Added native Stagehand agentic loop functionality. This allows you to build agentic workflows with a single prompt without using a computer-use model. To try it out, create a stagehand.agent without passing in a provider.

Patch Changes

1.14.0

Minor Changes

  • #518 516725f Thanks @sameelarif! - act() can now use observe() under the hood, resulting in significant performance improvements. To opt-in to this change, set slowDomBasedAct: false in ActOptions.

  • #483 8c9445f Thanks @seanmcguire12! - When using textExtract, you can now do targetted extraction by passing an xpath string into extract via the selector parameter. This limits the dom processing step to a target element, reducing tokens and increasing speed. For example:

    const weatherData = await stagehand.page.extract({
      instruction: "extract the weather data for Sun, Feb 23 at 11PM",
      schema: z.object({
        temperature: z.string(),
        weather_description: z.string(),
        wind: z.string(),
        humidity: z.string(),
        barometer: z.string(),
        visibility: z.string(),
      }),
      modelName,
      useTextExtract,
      selector: xpath, // xpath of the element to extract from
    });
  • #556 499a72d Thanks @kamath! - You can now set a timeout for dom-based stagehand act! Do this in act with timeoutMs as a parameter, or set a global param to actTimeoutMs in Stagehand config.

  • #544 55c9673 Thanks @seanmcguire12! - you can now deterministically get the full text representation of a webpage by calling extract() (with no arguments)

  • #538 d898d5b Thanks @sameelarif! - Added gpt-4.5-preview and claude-3-7-sonnet-latest as supported models.

  • #523 44cf7cc Thanks @kwt00! You can now natively run Cerebras LLMs! cerebras-llama-3.3-70b and cerebras-llama-3.1-8b are now supported models as long as CEREBRAS_API_KEY is set in your environment.

  • #542 cf7fe66 Thanks @sankalpgunturi! You can now natively run Groq LLMs! groq-llama-3.3-70b-versatile and groq-llama-3.3-70b-specdec are now supported models as long as GROQ_API_KEY is set in your environment.

Patch Changes

1.13.1

Patch Changes

1.13.0

Minor Changes

  • #486 33f2b3f Thanks @sameelarif! - [Unreleased] Parameterized offloading Stagehand method calls to the Stagehand API. In the future, this will allow for better observability and debugging experience.

  • #494 9ba4b0b Thanks @pkiv! - Added LocalBrowserLaunchOptions to provide comprehensive configuration options for local browser instances. Deprecated the top-level headless option in favor of using localBrowserLaunchOptions.headless

  • #500 a683fab Thanks @miguelg719! - Including Iframes in ObserveResults. This appends any iframe(s) found in the page to the end of observe results on any observe call.

  • #504 577662e Thanks @sameelarif! - Enabled support for Browserbase captcha solving after page navigations. This can be enabled with the new constructor parameter: waitForCaptchaSolves.

  • #496 28ca9fb Thanks @sameelarif! - Fixed browserbaseSessionCreateParams not being passed in to the API initialization payload.

Patch Changes

1.12.0

Minor Changes

  • #426 bbbcee7 Thanks @miguelg719! - Observe got a major upgrade. Now it will return a suggested playwright method with any necessary arguments for the generated candidate elements. It also includes a major speedup when using a11y tree processing for context.

  • #452 16837ec Thanks @kamath! - add o3-mini to availablemodel

  • #441 1032d7d Thanks @seanmcguire12! - allow act to accept observe output

Patch Changes

  • #458 da2e5d1 Thanks @miguelg719! - Updated getAccessibilityTree() to make sure it doesn't skip useful nodes. Improved getXPathByResolvedObjectId() to account for text nodes and not skip generation

  • #448 b216072 Thanks @seanmcguire12! - improve handling of radio button clicks

  • #445 5bc514f Thanks @miguelg719! - Adding back useAccessibilityTree param to observe with a deprecation warning/error indicating to use onlyVisible instead

1.11.0

Minor Changes

1.10.1

Patch Changes

  • #422 a2878d0 Thanks @miguelg719! - Fixing a build type error for async functions being called inside evaulate for observeHandler.

1.10.0

Minor Changes

  • #412 4aa4813 Thanks @miguelg719! - Includes a new format to get website context using accessibility (a11y) trees. The new context is provided optionally with the flag useAccessibilityTree for observe tasks.

  • #417 1f2b2c5 Thanks @sameelarif! - Simplify Stagehand method calls by allowing a simple string input instead of an options object.

  • #405 0df1e23 Thanks @seanmcguire12! - in ProcessAllOfDom, scroll on large scrollable elements instead of just the root DOM

  • #373 ff00965 Thanks @sameelarif! - Allow the input of custom instructions into the constructor so that users can guide, or provide guardrails to, the LLM in making decisions.

Patch Changes

1.9.0

Minor Changes

  • #374 207244e Thanks @sameelarif! - Pass in a Stagehand Page object into the on("popup") listener to allow for multi-page handling.

  • #367 75c0e20 Thanks @kamath! - Logger in LLMClient is inherited by default from Stagehand. Named rather than positional arguments are used in implemented LLMClients.

  • #381 db2ef59 Thanks @kamath! - make logs only sync

  • #385 5899ec2 Thanks @sameelarif! - Moved the LLMClient logger paremeter to the createChatCompletion method options.

  • #364 08907eb Thanks @kamath! - exposed llmClient in stagehand constructor

Patch Changes

1.8.0

Minor Changes

  • #324 cd23fa3 Thanks @kamath! - Move stagehand.act() -> stagehand.page.act() and deprecate stagehand.act()

  • #319 bacbe60 Thanks @kamath! - We now wrap playwright page/context within StagehandPage and StagehandContext objects. This helps us augment the Stagehand experience by being able to augment the underlying Playwright

  • #324 cd23fa3 Thanks @kamath! - moves extract and act -> page and deprecates stagehand.extract and stagehand.observe

Patch Changes

1.7.0

Minor Changes

  • #316 902e633 Thanks @kamath! - rename browserbaseResumeSessionID -> browserbaseSessionID

  • #296 f11da27 Thanks @kamath! - - Deprecate fields in init in favor of constructor options

    • Deprecate initFromPage in favor of browserbaseResumeSessionID in constructor
    • Rename browserBaseSessionCreateParams -> browserbaseSessionCreateParams
  • #304 0b72f75 Thanks @seanmcguire12! - add textExtract: an optional, text based approach to the existing extract method. textExtract often performs better on long form extraction tasks. By default extract uses the existing approach domExtract.

  • #298 55f0cd2 Thanks @kamath! - Add sessionId to public params

Patch Changes

1.6.0

Minor Changes

  • #286 9605836 Thanks @kamath! - minor improvement in action + new eval case

  • #279 d6d7057 Thanks @kamath! - Add support for o1-mini and o1-preview in OpenAIClient

  • #282 5291797 Thanks @kamath! - Added eslint for stricter type checking. Streamlined most of the internal types throughout the cache, llm, and handlers. This should make it easier to add new LLMs down the line, maintain and update the existing code, and make it easier to add new features in the future. Types can be checked by running npx eslint . from the project directory.

Patch Changes

1.5.0

Minor Changes

  • #266 0e8f34f Thanks @kamath! - Install wasn't working from NPM due to misconfigured build step. This attempts to fix that.

1.4.0

Minor Changes

Patch Changes

1.3.0

Minor Changes

  • #195 87a6305 Thanks @kamath! - - Adds structured and more standardized JSON logging
    • Doesn't init cache if enableCaching is false, preventing tmp/.cache from being created
    • Updates bundling for browser-side code to support NextJS and serverless

1.2.0

Minor Changes

  • #179 0031871 Thanks @navidkpr! - Fixes:

    The last big change we pushed out, introduced a small regression. As a result, the gray outline showing the elements Stagehand is looking out is missing. This commit fixes that. We now process selectorMap properly now (using the updated type Record<number, string[]

    Improved the action prompt:

    Improved the structure Made it more straightforward Improved working for completed arg and prioritized precision over recall

1.1.0

Minor Changes