You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .changeset/wise-worlds-pull.md
+21-1Lines changed: 21 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2,4 +2,24 @@
2
2
"@browserbasehq/stagehand": major
3
3
---
4
4
5
-
temporary placeholder
5
+
Announcing **Stagehand 2.0**! 🎉
6
+
7
+
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.
8
+
9
+
### 🚀 New Features
10
+
11
+
-**Introducing `stagehand.agent`**: A powerful new way to integrate SOTA Computer use models or Browserbase's [Open Operator](https://operator.browserbase.com) into Stagehand with one line of code! Perfect for multi-step workflows and complex interactions. [Learn more](https://docs.stagehand.dev/concepts/agent)
12
+
-**Lightning-fast `act` and `extract`**: Major performance improvements to make your automations run significantly faster.
13
+
-**Enhanced Logging**: Better visibility into what's happening during automation with improved logging and debugging capabilities.
14
+
-**Comprehensive Documentation**: A completely revamped documentation site with better examples, guides, and best practices.
15
+
-**Improved Error Handling**: More descriptive errors and better error recovery to help you debug issues faster.
16
+
17
+
### 🛠️ Developer Experience
18
+
19
+
-**Better TypeScript Support**: Enhanced type definitions and better IDE integration
20
+
-**Better Error Messages**: Clearer, more actionable error messages to help you debug faster
21
+
-**Improved Caching**: More reliable action caching for better performance
22
+
23
+
We're excited to see what you build with Stagehand 2.0! For questions or support, join our [Slack community](https://stagehand.dev/slack).
24
+
25
+
For more details, check out our [documentation](https://docs.stagehand.dev).
You can cache the results of `observe` and use them as params for `act` like this:
58
+
59
+
```typescript
60
+
const instruction = "Click the sign in button";
61
+
const cachedAction = await getCache(instruction);
62
+
63
+
if (cachedAction) {
64
+
await page.act(cachedAction);
65
+
} else {
66
+
try {
67
+
const results = await page.observe(instruction);
68
+
await setCache(instruction, results);
69
+
await page.act(results[0]);
70
+
} catch (error) {
71
+
await page.act(instruction); // If the action is not cached, execute the instruction directly
72
+
}
73
+
}
74
+
```
75
+
76
+
Be sure to cache the results of `observe` and use them as params for `act` to avoid unexpected DOM changes. Using `act` without caching will result in more unpredictable behavior.
77
+
78
+
Act `action` should be as atomic and specific as possible, i.e. "Click the sign in button" or "Type 'hello' into the search input".
79
+
AVOID actions that are more than one step, i.e. "Order me pizza" or "Type in the search bar and hit enter".
80
+
81
+
## Extract
82
+
83
+
If you are writing code that needs to extract data from the page, use Stagehand `extract`.
84
+
85
+
```typescript
86
+
const signInButtonText = await page.extract("extract the sign in button text");
87
+
```
88
+
89
+
You can also pass in params like an output schema in Zod, and a flag to use text extraction:
90
+
91
+
```typescript
92
+
const data = await page.extract({
93
+
instruction: "extract the sign in button text",
94
+
schema: z.object({
95
+
text: z.string(),
96
+
}),
97
+
});
98
+
```
99
+
100
+
`schema` is a Zod schema that describes the data you want to extract. To extract an array, make sure to pass in a single object that contains the array, as follows:
101
+
102
+
```typescript
103
+
const data = await page.extract({
104
+
instruction: "extract the text inside all buttons",
105
+
schema: z.object({
106
+
text: z.array(z.string()),
107
+
}),
108
+
useTextExtract: true, // Set true for larger-scale extractions (multiple paragraphs), or set false for small extractions (name, birthday, etc)
109
+
});
110
+
```
111
+
112
+
## Agent
113
+
114
+
Use the `agent` method to automonously execute larger tasks like "Get the stock price of NVDA"
Stagehand is the easiest way to build browser automations. It is fully compatible with [Playwright](https://playwright.dev/), offering three simple AI APIs (`act`, `extract`, and `observe`) on top of the base Playwright `Page` class that provide the building blocks for web automation via natural language.
38
+
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.
39
39
40
-
Here's a sample of what you can do with Stagehand:
40
+
1.**Choose when to write code vs. natural language**: use AI when you want to navigate unfamiliar pages, and use code ([Playwright](https://playwright.dev/)) when you know exactly what you want to do.
41
+
42
+
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.
43
+
44
+
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.
45
+
46
+
## Example
47
+
48
+
Here's how to build a sample browser automation with Stagehand:
49
+
50
+
<divalign="center">
51
+
<divstyle="max-width:300px;">
52
+
<img src="/media/github_demo.gif" alt="See Stagehand in Action">
53
+
</div>
54
+
</div>
41
55
42
56
```typescript
43
-
// Keep your existing Playwright code unchanged
44
-
awaitpage.goto("https://docs.stagehand.dev");
57
+
// Use Playwright functions on the page object
58
+
const page =stagehand.page;
59
+
awaitpage.goto("https://github.com/browserbase");
60
+
61
+
// Use act() to execute individual actions
62
+
awaitpage.act("click on the stagehand repo");
45
63
46
-
// Stagehand AI: Act on the page
47
-
awaitpage.act("click on the 'Quickstart'");
64
+
// Use Computer Use agents for larger actions
65
+
const agent =stagehand.agent({
66
+
provider: "openai",
67
+
model: "computer-use-preview",
68
+
});
69
+
awaitagent.execute("Get to the latest PR");
48
70
49
-
//Stagehand AI: Extract data from the page
50
-
const { description } =awaitpage.extract({
51
-
instruction: "extract the description of the page",
71
+
//Use extract() to read data from the page
72
+
const { author, title } =awaitpage.extract({
73
+
instruction: "extract the author and title of the PR",
52
74
schema: z.object({
53
-
description: z.string(),
75
+
author: z.string().describe("The username of the PR author"),
76
+
title: z.string().describe("The title of the PR"),
54
77
}),
55
78
});
56
79
```
57
80
58
-
> [!WARNING]
59
-
> We highly recommend using the Node.js runtime environment to run Stagehand scripts, as opposed to newer alternatives like Bun. This is solely due to the fact that [Bun's runtime is not yet fully compatible with Playwright](https://github.com/microsoft/playwright/issues/27139).
60
-
61
-
## Why?
62
-
**Stagehand adds determinism to otherwise unpredictable agents.**
63
-
64
-
While there's no limit to what you could instruct Stagehand to do, our primitives allow you to control how much you want to leave to an AI. It works best when your code is a sequence of atomic actions. Instead of writing a single script for a single website, Stagehand allows you to write durable, self-healing, and repeatable web automation workflows that actually work.
65
-
66
-
> [!NOTE]
67
-
> `Stagehand` is currently available as an early release, and we're actively seeking feedback from the community. Please join our [Slack community](https://stagehand.dev/slack) to stay updated on the latest developments and provide feedback.
68
-
69
81
## Documentation
70
82
71
83
Visit [docs.stagehand.dev](https://docs.stagehand.dev) to view the full documentation.
72
84
73
85
## Getting Started
74
86
87
+
Start with Stagehand with one line of code, or check out our [Quickstart Guide](https://docs.stagehand.dev/get_started/quickstart) for more information:
<p>Watch Anirudh demo create-browser-app to create a Stagehand project!</p>
@@ -81,23 +99,6 @@ Visit [docs.stagehand.dev](https://docs.stagehand.dev) to view the full document
81
99
</a>
82
100
</div>
83
101
84
-
### Quickstart
85
-
86
-
To create a new Stagehand project configured to our default settings, run:
87
-
88
-
```bash
89
-
npx create-browser-app --example quickstart
90
-
```
91
-
92
-
Read our [Quickstart Guide](https://docs.stagehand.dev/get_started/quickstart) in the docs for more information.
93
-
94
-
You can also add Stagehand to an existing Typescript project by running:
95
-
96
-
```bash
97
-
npm install @browserbasehq/stagehand zod
98
-
npx playwright install # if running locally
99
-
```
100
-
101
102
### Build and Run from Source
102
103
103
104
```bash
@@ -129,12 +130,15 @@ For more information, please see our [Contributing Guide](https://docs.stagehand
129
130
130
131
This project heavily relies on [Playwright](https://playwright.dev/) as a resilient backbone to automate the web. It also would not be possible without the awesome techniques and discoveries made by [tarsier](https://github.com/reworkd/tarsier), and [fuji-web](https://github.com/normal-computing/fuji-web).
131
132
132
-
We'd like to thank the following people for their contributions to Stagehand:
133
-
-[Jeremy Press](https://x.com/jeremypress) wrote the original MVP of Stagehand and continues to be an ally to the project.
134
-
-[Navid Pour](https://github.com/navidpour) is heavily responsible for the current architecture of Stagehand and the `act` API.
135
-
-[Sean McGuire](https://github.com/seanmcguire12) is a major contributor to the project and has been a great help with improving the `extract` API and getting evals to a high level.
136
-
-[Filip Michalsky](https://github.com/filip-michalsky) has been doing a lot of work on building out integrations like [Langchain](https://js.langchain.com/docs/integrations/tools/stagehand/) and [Claude MCP](https://github.com/browserbase/mcp-server-browserbase), generally improving the repository, and unblocking users.
137
-
-[Sameel Arif](https://github.com/sameelarif) is a major contributor to the project, especially around improving the developer experience.
133
+
We'd like to thank the following people for their major contributions to Stagehand:
0 commit comments