Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/browserbase/stagehand/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The Stagehand class (also exported as V3) is the primary interface for browser automation. It orchestrates browser sessions (local or Browserbase), manages LLM clients, and provides high-level methods for AI-driven web interaction.

Constructor

const stagehand = new Stagehand(options: V3Options);
options
V3Options
required
Configuration object for initializing Stagehand

Instance Methods

init()

Initialize the browser session and connect to CDP.
await stagehand.init();
returns
Promise<void>
Resolves when browser is ready

close()

Close the browser and clean up resources.
await stagehand.close(options?);
options.force
boolean
Force immediate shutdown

act()

Perform an action on the page using natural language. See act() method reference for detailed documentation.

extract()

Extract structured data from the page. See extract() method reference for detailed documentation.

observe()

Find elements on the page matching a description. See observe() method reference for detailed documentation.

agent()

Create an autonomous agent to complete multi-step tasks. See Agent class reference for detailed documentation.

Properties

context

context
V3Context
required
The CDP context managing browser connections and pages

llmClient

llmClient
LLMClient
required
The LLM client used for AI operations

metrics

metrics
Promise<StagehandMetrics>
required
Token usage and performance metrics (async property)

history

history
Promise<ReadonlyArray<HistoryEntry>>
required
History of all operations performed (async property)

isBrowserbase

isBrowserbase
boolean
required
Whether running on Browserbase

browserbaseSessionID

browserbaseSessionID
string | undefined
Current Browserbase session ID

Example

import { Stagehand } from "@browserbasehq/stagehand";

const stagehand = new Stagehand({
  env: "LOCAL",
  verbose: 1,
  model: "openai/gpt-4.1-mini",
});

await stagehand.init();

const page = await stagehand.context.newPage();
await page.goto("https://example.com");

await stagehand.act("click the login button");
await stagehand.act("fill in username with 'user@example.com'");

await stagehand.close();