# AI use cases for Stagehand (browserbase/stagehand)

Repo: [browserbase/stagehand](https://github.com/browserbase/stagehand) | Use cases: 3 | Page: https://dedupedai.com/use-cases/browserbase-stagehand/

Stagehand is Browserbase's SDK for browser agents in TypeScript, Python and Go. It adds three AI methods to Playwright-style browser control: act to perform an action described in plain language, observe to find real selectors on the page, and extract to pull schema-validated data. Actions self-heal when a site changes, sessions persist in a user data directory, and the same script can run locally or on Browserbase.

This file holds every use case of this repo. Each one starts with a "## " heading and ends with its URL.

- Pull structured data from a site with a schema: https://dedupedai.com/use-cases/browserbase-stagehand/extract-structured-data-from-any-website/
- Automate a logged-in workflow without giving the model your password: https://dedupedai.com/use-cases/browserbase-stagehand/automate-a-logged-in-workflow-safely/
- Run browser automations in the cloud with action caching: https://dedupedai.com/use-cases/browserbase-stagehand/run-browser-agents-on-browserbase-with-caching/

## How to pull structured data from a site with a schema with Stagehand

Repo: [browserbase/stagehand](https://github.com/browserbase/stagehand) | Difficulty: Beginner | Time: 30 minutes | Basis: From the README

Use extract with a Zod or Pydantic schema to get typed data out of any page.

**Who it is for:** A developer who needs a table of prices, invoices or listings from a site with no API.

**The problem:** Hand-written scrapers break whenever the page layout changes and return messy text.

**The outcome:** Schema-validated JSON from the page, ready to save or feed into another system.

### Steps

1. Install with `pnpm add @browserbasehq/stagehand 'zod@~4.4.3'` or `pip install stagehand`
2. Launch a local browser and create a Stagehand instance with your model and API key
3. Navigate with page.goto to the page you want
4. Call Stagehand.extract with an instruction such as extract every invoice in the table and a schema describing the fields
5. Use the returned data, which is validated against your schema

### Prompt to paste into your agent

```text
Using browserbase/stagehand in <TypeScript or Python>, write a script that opens <url>, extracts every <item> on the page into a schema with fields <fields>, and saves the result as JSON. Read the API key from the environment.
```

### Caveat

Respect each site's terms of service and robots rules when you extract data.

Risk, credentials: You supply a model API key and every extract call costs tokens; keep keys in environment variables, not in code.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/browserbase-stagehand/extract-structured-data-from-any-website/

## How to automate a logged-in workflow without giving the model your password with Stagehand

Repo: [browserbase/stagehand](https://github.com/browserbase/stagehand) | Difficulty: Intermediate | Time: 1 hour | Basis: From the README

Use observe to find login fields and fill them yourself, then let act drive the rest of the task.

**Who it is for:** Someone automating a dull task inside a web app they log into, like downloading monthly invoices.

**The problem:** Letting an AI agent type your password means the credentials pass through the model.

**The outcome:** A script that signs in once, keeps the session in ./browser-data and repeats the task on later runs.

### Steps

1. Install Stagehand and make sure Chrome is installed locally
2. Launch the local browser with a userDataDir such as ./browser-data so cookies persist between runs
3. Call Stagehand.observe to find the email and password inputs, then fill them from environment variables with page.locator; observe returns real selectors, so credentials never reach the model
4. Use Stagehand.act for steps like click the sign in button and open the billing page
5. Run it again later: the next run starts already signed in

### Prompt to paste into your agent

```text
Build a browserbase/stagehand script for <web app> that signs in using observe plus locator fill with credentials from environment variables, keeps the session in ./browser-data, then uses act to <task steps> and extract to save <data>. Never pass the password to the model.
```

### Caveat

Automating a site you log into may break its terms of service, so check before running it on a schedule.

Risk, credentials: The persisted browser-data folder holds live session cookies; store it like a password and keep it out of version control.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/browserbase-stagehand/automate-a-logged-in-workflow-safely/

## How to run browser automations in the cloud with action caching with Stagehand

Repo: [browserbase/stagehand](https://github.com/browserbase/stagehand) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Point the same Stagehand script at Browserbase and turn on caching so repeated actions spend no tokens.

**Who it is for:** A team running the same browser automations many times a day who wants them faster and cheaper.

**The problem:** Running browsers on your own servers is fiddly, and paying model tokens for the same action every run adds up.

**The outcome:** The same script running on hosted browsers, with repeated calls served from cache.

### Steps

1. Get a Browserbase API key and set BROWSERBASE_API_KEY
2. Launch with browserbase.launch instead of the local browser, keeping the rest of your script
3. Create Stagehand with cache: true so identical calls come back from Browserbase with no tokens spent
4. Leave out the model configuration to let the Model Gateway pick the cheapest model for each action
5. Use session recordings to debug runs that go wrong

### Prompt to paste into your agent

```text
Move my existing browserbase/stagehand script <file> from a local browser to Browserbase: launch with browserbase.launch using BROWSERBASE_API_KEY, enable cache, drop the model config so the Model Gateway picks models, and run it twice to show the second run uses the cache.
```

### Caveat

Caching only helps when the same call repeats; one-off tasks still pay for model tokens.

Risk, credentials: This needs a Browserbase API key on a paid hosted service; keep it in an environment variable and check pricing before moving high-volume jobs.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/browserbase-stagehand/run-browser-agents-on-browserbase-with-caching/
