Stagehand.create(). There are three ways to get one:
- Browserbase (
browserbase.launch): Cloud-managed browser infrastructure optimized for production web automation at scale - Local (
localBrowser.launch): Run browsers directly on your machine for development and debugging - Attach over CDP (
localBrowser.connect): Attach to any Chromium browser you are already running, by URL
browser.close() is yours to call.
- TypeScript
- Python
- Go
Browserbase environment
Browserbase provides managed cloud browser infrastructure optimized for web automation at scale. It offers advanced features like stealth mode, proxy support, and persistent contexts. It is also the only browser that supports server-side caching and the Model Gateway.Browserbase
Read the Browserbase documentation for the full set of session settings Stagehand passes through.
Multi-region support
Browserbase runs browsers in four regions, so you can cut latency by starting the browser near your users or your target site, and keep session data in a required jurisdiction. Set the region onbrowserbase.launch(); us-west-2 is the default.
- TypeScript
- Python
- Go
us-west-2 (default), us-east-1, eu-central-1, ap-southeast-1.
You normally do not need to configure a regional endpoint. Stagehand picks the API deployment that matches your session’s region on its own, including for server-side caching. An explicit Stagehand
apiUrl overrides that regional selection.API endpoint overrides
Browserbase session management and Stagehand managed services use separate APIs. Both default to the production service. The SDKs do not read either URL from an environment variable. PassbaseUrl to Browserbase and apiUrl to Stagehand when testing another deployment. Use the service origin without /v1.
- TypeScript
- Python
- Go
browserbase.launch() and browserbase.connect() make. The Stagehand URL controls Model Gateway and managed-cache requests that the browser runtime makes.
Browserbase client options
browserbase.launch() and browserbase.connect() create a Browserbase client for session and extension requests. Pass clientOptions (TypeScript), client_options (Python), or ClientOptions (Go) to tune that client’s timeout, retries, default headers, and default query parameters. TypeScript also accepts a custom fetch, Python accepts an httpx.AsyncClient as http_client, and Go accepts an *http.Client as HTTPClient. apiKey and baseUrl stay top-level, so one key authenticates both Browserbase and Stagehand.
- TypeScript
- Python
- Go
time.Duration that bounds each attempt. Stagehand never closes an http_client you pass; keep it open until browser.close() returns, because releasing the session uses it. Go never modifies an HTTPClient you pass, so its own Timeout and Transport still apply. In every SDK, default headers override the client’s own headers on conflict, including X-BB-API-Key and User-Agent. Go rejects invalid header names or values before sending any request.
Environment variables
Before getting started, set up the required environment variables:Using Stagehand with Browserbase
Basic setup
The simplest way to get started is with default settings.browserbase.launch() needs nothing but your Browserbase API key:
- TypeScript
- Python
- Go
Advanced configuration
Configure browser settings, proxy support, and other session parameters directly onbrowserbase.launch():
- TypeScript
- Python
- Go
Advanced Browserbase configuration example
Advanced Browserbase configuration example
- TypeScript
- Python
- Go
When
browserbase.launch() creates a session without an extensionId, Stagehand uploads its extension and starts the session against it. Stagehand deletes the upload when you call browser.close() for a launched session.Alternative: Browserbase SDK
If you prefer to manage sessions directly, export the Stagehand extension and upload it to Browserbase first and include that uploaded extension when you create the session. Extensions cannot be added after a browser session starts. You can then hand Stagehand the resulting session throughbrowserbase.connect():
The extension ID used to create the session is the uploaded-extension resource ID returned by the Browserbase Extensions API.
browserbase.launch() handles this upload and session configuration automatically.- TypeScript
- Python
- Go
Connecting over CDP
localBrowser.connect() attaches to a running Chromium browser through its DevTools endpoint. It discovers an installed Stagehand extension first, then loads the bundled extension if none is found or discovery is unsupported. Loading requires a shared filesystem. For Browserbase sessions, use browserbase.connect() with the session ID; the extension must already be installed.
Connect-time
extensionId / extension_id / ExtensionID is deprecated and ignored.- TypeScript
- Python
- Go
Connecting with authentication headers
If the browser service you connect to requires authentication headers, pass them usingheaders (TypeScript and Python) or Headers (Go). This lets you authenticate without putting credentials in the connection URL.
- TypeScript
- Python
- Go
- Headers are sent with HTTP discovery and the client’s WebSocket connection. They are only forwarded to the same host and port, without switching from a secure connection to an insecure one.
- Headers are never passed to the extension. Its connection must work without them, using a signed URL or a separate CDP URL.
A separate CDP URL for the extension
If the client connects through a proxy or authenticated gateway, you can give the extension a separate browser-level CDP WebSocket URL:- TypeScript
- Python
- Go
ws:// or wss://, include a host, and use a port between 1 and 65535 if specified. Both endpoints must reach the same browser. When the option is omitted (None in Python or an empty string in Go), the extension uses the client’s resolved CDP WebSocket URL.
In this example, 127.0.0.1 refers to the browser’s environment. The extension can use any host reachable from inside Chrome. Using a separate endpoint keeps the gateway URL and its credentials out of the extension and avoids routing the extension’s CDP commands through the gateway.
Stagehand never closes a browser it did not launch. When you connect to an existing browser,
close() tears down the Stagehand connection and leaves the browser running.Local environment
Run browsers directly on your machine when you want full control over the browser process and its launch flags. This suits development, debugging, and custom browser setups.Environment comparison
Basic local setup
- TypeScript
- Python
- Go
Advanced local configuration
Customize browser launch options for local development:- TypeScript
- Python
- Go
Authenticated local proxies are not supported yet. Setting a proxy
username or password raises in all three SDKs; a proxy server and bypass list work everywhere.Default local launch arguments
When Stagehand launches a local browser, it adds the following Chrome arguments before any values you pass in the launchargs:
- TypeScript
- Python
- Go
--enable-unsafe-extension-debugging is required so the SDK can attach a CDP session to the service worker hosting Stagehand’s runtime. Chrome blocks debugger access to extension targets without it. --enable-features=WebMCP,WebMCPTesting,DevToolsWebMCPSupport turns on the browser support behind WebMCP across supported Chrome versions. --window-size follows the viewport option and falls back to 1280,800 when you do not set one.- TypeScript
- Python
- Go
true to remove all default arguments. Use a list to remove only exact matches while preserving the rest.
Exporting the Stagehand extension
Each SDK exposes the extension bundled with its installed version as ZIP bytes. Use this archive to upload the extension to Browserbase or extract it for local installation in Chrome. These helpers do not require a Stagehand instance or a browser session and do not write files themselves.- TypeScript
- Python
- Go
getExtensionArchive() returns Promise<Uint8Array>.Upload to Browserbase
Uploadstagehand-extension.zip using the Browserbase Extensions API or the CLI deployment workflow. Include the returned extension ID when creating the session, as shown in Alternative: Browserbase SDK. browserbase.launch() handles the upload automatically when you omit an extension ID.
Load unpacked in Chrome
- Extract
stagehand-extension.zipto a folder. - Open
chrome://extensionsand enable Developer mode. - Click Load unpacked and select the extracted folder containing
manifest.json.
manifest.json at its root. Load unpacked requires the extracted files on disk; it cannot accept ZIP bytes or a ZIP file directly. Keep the extracted folder available while the extension is installed.
You can also extract the archive directly from Python:
stagehand-extension folder in Load unpacked. To attach Stagehand to that browser, it must also expose a DevTools endpoint; see Connecting over CDP.
Advanced configuration
Keep alive
Keep-alive keeps a launched browser running afterstagehand.close() or after your script exits, so you can reconnect to it later. Call browser.close() when you’re done. It closes the browser even with keep-alive on.
Keeping sessions alive is available on the Browserbase Startup plan and above.
- TypeScript
- Python
- Go
Behavior by environment
Local environment
When running locally with keep-alive on, Stagehand leaves the Chrome process running when your script exits. This is useful for debugging or for handing off a browser session to another process. Combine it with a fixedport so you can reattach with localBrowser.connect().
- TypeScript
- Python
- Go
A temporary user data directory is deleted when a local browser shuts down. Set
userDataDir (or turn on the preserve option) if you want the profile to survive.Fixed CDP debugging port
Specify a fixed Chrome DevTools Protocol (CDP) debugging port instead of using a randomly assigned one.- TypeScript
- Python
- Go
DOM settle timeout
Configure how long Stagehand waits for the DOM to stabilize before taking actions. The default is 5000 ms.- TypeScript
- Python
- Go
DOM settling applies to
act() calls that take a natural-language instruction. Replaying an observed Action skips the wait, and observe() and extract() read a snapshot of the page as they find it.What is DOM settling?
Before an instruction-basedact() call runs, Stagehand waits for the page’s network activity to go quiet, up to the timeout. That gives lazy-loaded content, JavaScript updates, and other dynamic rendering time to finish before the action targets an element.
When to adjust
Increase the DOM settle timeout for pages with:- Heavy animations or transitions
- Lazy-loading or infinite scroll
- Dynamic JavaScript frameworks (React, Vue, Angular)
- Complex single-page applications
- TypeScript
- Python
- Go
Troubleshooting
Browserbase authentication errors
Browserbase authentication errors
- Verify your
BROWSERBASE_API_KEYis read and passed tobrowserbase.launch() - Check that your API key has the necessary permissions
- Ensure your Browserbase account has sufficient credits
- Remember that
browserbase.launch()requires an API key: it fails without one
Local browser launch failures
Local browser launch failures
- Install Chrome or Chromium on your system
- Set the correct executable path for your Chrome installation, or set
CHROME_PATH - Check that required dependencies are installed (Linux:
libnss3-dev libatk-bridge2.0-dev libgtk-3-dev libxss1 libasound2) - If the extension fails to load, confirm nothing is stripping
--enable-unsafe-extension-debuggingfrom the launch arguments
Session timeout issues
Session timeout issues
- Increase the session timeout on
browserbase.launch() - Turn on keep-alive for long-running sessions
- Monitor session usage to avoid unexpected terminations

