@mastra/agent-browser 0.0.0-a2a-vnext-20260424123427
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +129 -0
- package/LICENSE.md +30 -0
- package/README.md +138 -0
- package/dist/index.cjs +1640 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +627 -0
- package/dist/index.d.ts +627 -0
- package/dist/index.js +1619 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# @mastra/agent-browser
|
|
2
|
+
|
|
3
|
+
## 0.0.0-a2a-vnext-20260424123427
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`092271d`](https://github.com/mastra-ai/mastra/commit/092271d86af4cbe0d70cbf32709dd99b58acd3dd)]:
|
|
8
|
+
- @mastra/core@0.0.0-a2a-vnext-20260424123427
|
|
9
|
+
|
|
10
|
+
## 0.2.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Standardize `headless` default to `true` across all browser providers. Each provider now resolves `headless` once in its constructor and passes it to the thread manager via the base class getter, removing duplicate fallback logic. ([#15696](https://github.com/mastra-ai/mastra/pull/15696))
|
|
15
|
+
|
|
16
|
+
- Fixed `browser_evaluate` so expression scripts now return their computed value instead of `undefined` (for example, `document.querySelectorAll('a').length`). ([#15689](https://github.com/mastra-ai/mastra/pull/15689))
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`733bf53`](https://github.com/mastra-ai/mastra/commit/733bf53d9352aedd3ef38c3d501edb275b65b43c), [`5405b3b`](https://github.com/mastra-ai/mastra/commit/5405b3b35325c5b8fb34fc7ac109bd2feb7bb6fe), [`45e29cb`](https://github.com/mastra-ai/mastra/commit/45e29cb5b5737f3083eb3852db02b944b9cf37ed), [`750b4d3`](https://github.com/mastra-ai/mastra/commit/750b4d3d8231f92e769b2c485921ac5a8ca639b9), [`c321127`](https://github.com/mastra-ai/mastra/commit/c3211275fc195de9ad1ead2746b354beb8eae6e8), [`a07bcef`](https://github.com/mastra-ai/mastra/commit/a07bcefea77c03d6d322caad973dca49b4b15fa1), [`696694e`](https://github.com/mastra-ai/mastra/commit/696694e00f29241a25dd1a1b749afa06c3a626b4), [`b084a80`](https://github.com/mastra-ai/mastra/commit/b084a800db0f82d62e1fc3d6e3e3480da1ba5a53), [`82b7a96`](https://github.com/mastra-ai/mastra/commit/82b7a964169636c1d1e0c694fc892a213b0179d5), [`df97812`](https://github.com/mastra-ai/mastra/commit/df97812bd949dcafeb074b80ecab501724b49c3b), [`8bbe360`](https://github.com/mastra-ai/mastra/commit/8bbe36042af7fc4be0244dffd8913f6795179421), [`f6b8ba8`](https://github.com/mastra-ai/mastra/commit/f6b8ba8dbf533b7a8db90c72b6805ddc804a3a72), [`a07bcef`](https://github.com/mastra-ai/mastra/commit/a07bcefea77c03d6d322caad973dca49b4b15fa1)]:
|
|
19
|
+
- @mastra/core@1.28.0
|
|
20
|
+
|
|
21
|
+
## 0.2.1-alpha.1
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Standardize `headless` default to `true` across all browser providers. Each provider now resolves `headless` once in its constructor and passes it to the thread manager via the base class getter, removing duplicate fallback logic. ([#15696](https://github.com/mastra-ai/mastra/pull/15696))
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [[`750b4d3`](https://github.com/mastra-ai/mastra/commit/750b4d3d8231f92e769b2c485921ac5a8ca639b9)]:
|
|
28
|
+
- @mastra/core@1.28.0-alpha.1
|
|
29
|
+
|
|
30
|
+
## 0.2.1-alpha.0
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Fixed `browser_evaluate` so expression scripts now return their computed value instead of `undefined` (for example, `document.querySelectorAll('a').length`). ([#15689](https://github.com/mastra-ai/mastra/pull/15689))
|
|
35
|
+
|
|
36
|
+
- Updated dependencies [[`733bf53`](https://github.com/mastra-ai/mastra/commit/733bf53d9352aedd3ef38c3d501edb275b65b43c), [`5405b3b`](https://github.com/mastra-ai/mastra/commit/5405b3b35325c5b8fb34fc7ac109bd2feb7bb6fe), [`c321127`](https://github.com/mastra-ai/mastra/commit/c3211275fc195de9ad1ead2746b354beb8eae6e8), [`a07bcef`](https://github.com/mastra-ai/mastra/commit/a07bcefea77c03d6d322caad973dca49b4b15fa1), [`b084a80`](https://github.com/mastra-ai/mastra/commit/b084a800db0f82d62e1fc3d6e3e3480da1ba5a53), [`82b7a96`](https://github.com/mastra-ai/mastra/commit/82b7a964169636c1d1e0c694fc892a213b0179d5), [`df97812`](https://github.com/mastra-ai/mastra/commit/df97812bd949dcafeb074b80ecab501724b49c3b), [`8bbe360`](https://github.com/mastra-ai/mastra/commit/8bbe36042af7fc4be0244dffd8913f6795179421), [`f6b8ba8`](https://github.com/mastra-ai/mastra/commit/f6b8ba8dbf533b7a8db90c72b6805ddc804a3a72), [`a07bcef`](https://github.com/mastra-ai/mastra/commit/a07bcefea77c03d6d322caad973dca49b4b15fa1)]:
|
|
37
|
+
- @mastra/core@1.28.0-alpha.0
|
|
38
|
+
|
|
39
|
+
## 0.2.0
|
|
40
|
+
|
|
41
|
+
### Minor Changes
|
|
42
|
+
|
|
43
|
+
- Added `storageState` option and `exportStorageState()` method for lightweight auth persistence (cookies and localStorage). Also kills orphaned Chrome child processes on close to prevent zombies. ([#15194](https://github.com/mastra-ai/mastra/pull/15194))
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- AgentBrowser with default thread scope now initializes correctly. Previously, calling launch() followed by getPage() would throw "Browser not launched" when no explicit thread ID was provided. ([#15285](https://github.com/mastra-ai/mastra/pull/15285))
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [[`87df955`](https://github.com/mastra-ai/mastra/commit/87df955c028660c075873fd5d74af28233ce32eb), [`8fad147`](https://github.com/mastra-ai/mastra/commit/8fad14759804179c8e080ce4d9dec6ef1a808b31), [`582644c`](https://github.com/mastra-ai/mastra/commit/582644c4a87f83b4f245a84d72b9e8590585012e), [`cbdf3e1`](https://github.com/mastra-ai/mastra/commit/cbdf3e12b3d0c30a6e5347be658e2009648c130a), [`8fe46d3`](https://github.com/mastra-ai/mastra/commit/8fe46d354027f3f0f0846e64219772348de106dd), [`18c67db`](https://github.com/mastra-ai/mastra/commit/18c67dbb9c9ebc26f26f65f7d3ff836e5691ef46), [`4ba3bb1`](https://github.com/mastra-ai/mastra/commit/4ba3bb1e465ad2ddaba3bbf2bc47e0faec32985e), [`5d84914`](https://github.com/mastra-ai/mastra/commit/5d84914e0e520c642a40329b210b413fcd139898), [`8dcc77e`](https://github.com/mastra-ai/mastra/commit/8dcc77e78a5340f5848f74b9e9f1b3da3513c1f5), [`aa67fc5`](https://github.com/mastra-ai/mastra/commit/aa67fc59ee8a5eeff1f23eb05970b8d7a536c8ff), [`fd2f314`](https://github.com/mastra-ai/mastra/commit/fd2f31473d3449b6b97e837ef8641264377f41a7), [`fa8140b`](https://github.com/mastra-ai/mastra/commit/fa8140bcd4251d2e3ac85fdc5547dfc4f372b5be), [`190f452`](https://github.com/mastra-ai/mastra/commit/190f45258b0640e2adfc8219fa3258cdc5b8f071), [`e80fead`](https://github.com/mastra-ai/mastra/commit/e80fead1412cc0d1b2f7d6a1ce5017d9e0098ff7), [`0287b64`](https://github.com/mastra-ai/mastra/commit/0287b644a5c3272755cf3112e71338106664103b), [`7e7bf60`](https://github.com/mastra-ai/mastra/commit/7e7bf606886bf374a6f9d4ca9b09dd83d0533372), [`184907d`](https://github.com/mastra-ai/mastra/commit/184907d775d8609c03c26e78ccaf37315f3aa287), [`075e91a`](https://github.com/mastra-ai/mastra/commit/075e91a4549baf46ad7a42a6a8ac8dfa78cc09e6), [`0c4cd13`](https://github.com/mastra-ai/mastra/commit/0c4cd131931c04ac5405373c932a242dbe88edd6), [`b16a753`](https://github.com/mastra-ai/mastra/commit/b16a753d5748440248d7df82e29bb987a9c8386c)]:
|
|
50
|
+
- @mastra/core@1.25.0
|
|
51
|
+
|
|
52
|
+
## 0.2.0-alpha.0
|
|
53
|
+
|
|
54
|
+
### Minor Changes
|
|
55
|
+
|
|
56
|
+
- Added `storageState` option and `exportStorageState()` method for lightweight auth persistence (cookies and localStorage). Also kills orphaned Chrome child processes on close to prevent zombies. ([#15194](https://github.com/mastra-ai/mastra/pull/15194))
|
|
57
|
+
|
|
58
|
+
### Patch Changes
|
|
59
|
+
|
|
60
|
+
- AgentBrowser with default thread scope now initializes correctly. Previously, calling launch() followed by getPage() would throw "Browser not launched" when no explicit thread ID was provided. ([#15285](https://github.com/mastra-ai/mastra/pull/15285))
|
|
61
|
+
|
|
62
|
+
- Updated dependencies [[`cbdf3e1`](https://github.com/mastra-ai/mastra/commit/cbdf3e12b3d0c30a6e5347be658e2009648c130a), [`8fe46d3`](https://github.com/mastra-ai/mastra/commit/8fe46d354027f3f0f0846e64219772348de106dd), [`18c67db`](https://github.com/mastra-ai/mastra/commit/18c67dbb9c9ebc26f26f65f7d3ff836e5691ef46), [`8dcc77e`](https://github.com/mastra-ai/mastra/commit/8dcc77e78a5340f5848f74b9e9f1b3da3513c1f5), [`aa67fc5`](https://github.com/mastra-ai/mastra/commit/aa67fc59ee8a5eeff1f23eb05970b8d7a536c8ff), [`fa8140b`](https://github.com/mastra-ai/mastra/commit/fa8140bcd4251d2e3ac85fdc5547dfc4f372b5be), [`190f452`](https://github.com/mastra-ai/mastra/commit/190f45258b0640e2adfc8219fa3258cdc5b8f071), [`7e7bf60`](https://github.com/mastra-ai/mastra/commit/7e7bf606886bf374a6f9d4ca9b09dd83d0533372), [`184907d`](https://github.com/mastra-ai/mastra/commit/184907d775d8609c03c26e78ccaf37315f3aa287), [`0c4cd13`](https://github.com/mastra-ai/mastra/commit/0c4cd131931c04ac5405373c932a242dbe88edd6), [`b16a753`](https://github.com/mastra-ai/mastra/commit/b16a753d5748440248d7df82e29bb987a9c8386c)]:
|
|
63
|
+
- @mastra/core@1.25.0-alpha.3
|
|
64
|
+
|
|
65
|
+
## 0.1.0
|
|
66
|
+
|
|
67
|
+
### Minor Changes
|
|
68
|
+
|
|
69
|
+
- Add browser automation support with screencast streaming, input injection, and thread isolation ([#14938](https://github.com/mastra-ai/mastra/pull/14938))
|
|
70
|
+
|
|
71
|
+
**New Features:**
|
|
72
|
+
- Browser tools for web automation (navigate, click, type, scroll, extract, etc.)
|
|
73
|
+
- Real-time screencast streaming via WebSocket
|
|
74
|
+
- Mouse and keyboard input injection
|
|
75
|
+
- Thread-scoped browser isolation (`scope: 'thread'`)
|
|
76
|
+
- State persistence and restoration across sessions
|
|
77
|
+
- Support for cloud providers (Browserbase, Browser-Use, Browserless)
|
|
78
|
+
|
|
79
|
+
**Configuration:**
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { AgentBrowser } from '@mastra/agent-browser';
|
|
83
|
+
|
|
84
|
+
const browser = new AgentBrowser({
|
|
85
|
+
headless: true,
|
|
86
|
+
scope: 'thread', // Each thread gets isolated browser
|
|
87
|
+
viewport: { width: 1280, height: 720 },
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const agent = mastra.getAgent('my-agent', { browser });
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Patch Changes
|
|
94
|
+
|
|
95
|
+
- Updated dependencies [[`cb15509`](https://github.com/mastra-ai/mastra/commit/cb15509b58f6a83e11b765c945082afc027db972), [`81e4259`](https://github.com/mastra-ai/mastra/commit/81e425939b4ceeb4f586e9b6d89c3b1c1f2d2fe7), [`951b8a1`](https://github.com/mastra-ai/mastra/commit/951b8a1b5ef7e1474c59dc4f2b9fc1a8b1e508b6), [`80c5668`](https://github.com/mastra-ai/mastra/commit/80c5668e365470d3a96d3e953868fd7a643ff67c), [`3d478c1`](https://github.com/mastra-ai/mastra/commit/3d478c1e13f17b80f330ac49d7aa42ef929b93ff), [`2b4ea10`](https://github.com/mastra-ai/mastra/commit/2b4ea10b053e4ea1ab232d536933a4a3c4cba999), [`a0544f0`](https://github.com/mastra-ai/mastra/commit/a0544f0a1e6bd52ac12676228967c1938e43648d), [`6039f17`](https://github.com/mastra-ai/mastra/commit/6039f176f9c457304825ff1df8c83b8e457376c0), [`06b928d`](https://github.com/mastra-ai/mastra/commit/06b928dfc2f5630d023467476cc5919dfa858d0a), [`6a8d984`](https://github.com/mastra-ai/mastra/commit/6a8d9841f2933456ee1598099f488d742b600054), [`c8c86aa`](https://github.com/mastra-ai/mastra/commit/c8c86aa1458017fbd1c0776fdc0c520d129df8a6)]:
|
|
96
|
+
- @mastra/core@1.22.0
|
|
97
|
+
|
|
98
|
+
## 0.1.0-alpha.0
|
|
99
|
+
|
|
100
|
+
### Minor Changes
|
|
101
|
+
|
|
102
|
+
- Add browser automation support with screencast streaming, input injection, and thread isolation ([#14938](https://github.com/mastra-ai/mastra/pull/14938))
|
|
103
|
+
|
|
104
|
+
**New Features:**
|
|
105
|
+
- Browser tools for web automation (navigate, click, type, scroll, extract, etc.)
|
|
106
|
+
- Real-time screencast streaming via WebSocket
|
|
107
|
+
- Mouse and keyboard input injection
|
|
108
|
+
- Thread-scoped browser isolation (`scope: 'thread'`)
|
|
109
|
+
- State persistence and restoration across sessions
|
|
110
|
+
- Support for cloud providers (Browserbase, Browser-Use, Browserless)
|
|
111
|
+
|
|
112
|
+
**Configuration:**
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { AgentBrowser } from '@mastra/agent-browser';
|
|
116
|
+
|
|
117
|
+
const browser = new AgentBrowser({
|
|
118
|
+
headless: true,
|
|
119
|
+
scope: 'thread', // Each thread gets isolated browser
|
|
120
|
+
viewport: { width: 1280, height: 720 },
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const agent = mastra.getAgent('my-agent', { browser });
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Patch Changes
|
|
127
|
+
|
|
128
|
+
- Updated dependencies [[`cb15509`](https://github.com/mastra-ai/mastra/commit/cb15509b58f6a83e11b765c945082afc027db972), [`80c5668`](https://github.com/mastra-ai/mastra/commit/80c5668e365470d3a96d3e953868fd7a643ff67c), [`3d478c1`](https://github.com/mastra-ai/mastra/commit/3d478c1e13f17b80f330ac49d7aa42ef929b93ff), [`6039f17`](https://github.com/mastra-ai/mastra/commit/6039f176f9c457304825ff1df8c83b8e457376c0), [`06b928d`](https://github.com/mastra-ai/mastra/commit/06b928dfc2f5630d023467476cc5919dfa858d0a), [`6a8d984`](https://github.com/mastra-ai/mastra/commit/6a8d9841f2933456ee1598099f488d742b600054)]:
|
|
129
|
+
- @mastra/core@1.22.0-alpha.2
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Portions of this software are licensed as follows:
|
|
2
|
+
|
|
3
|
+
- All content that resides under any directory named "ee/" within this
|
|
4
|
+
repository, including but not limited to:
|
|
5
|
+
- `packages/core/src/auth/ee/`
|
|
6
|
+
- `packages/server/src/server/auth/ee/`
|
|
7
|
+
is licensed under the license defined in `ee/LICENSE`.
|
|
8
|
+
|
|
9
|
+
- All third-party components incorporated into the Mastra Software are
|
|
10
|
+
licensed under the original license provided by the owner of the
|
|
11
|
+
applicable component.
|
|
12
|
+
|
|
13
|
+
- Content outside of the above-mentioned directories or restrictions is
|
|
14
|
+
available under the "Apache License 2.0" as defined below.
|
|
15
|
+
|
|
16
|
+
# Apache License 2.0
|
|
17
|
+
|
|
18
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
19
|
+
|
|
20
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
you may not use this file except in compliance with the License.
|
|
22
|
+
You may obtain a copy of the License at
|
|
23
|
+
|
|
24
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
+
|
|
26
|
+
Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
See the License for the specific language governing permissions and
|
|
30
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# @mastra/agent-browser
|
|
2
|
+
|
|
3
|
+
Deterministic browser automation for Mastra agents using [agent-browser](https://github.com/vercel-labs/agent-browser).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mastra/agent-browser
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Agent } from '@mastra/core/agent';
|
|
15
|
+
import { AgentBrowser } from '@mastra/agent-browser';
|
|
16
|
+
|
|
17
|
+
// Create an AgentBrowser instance
|
|
18
|
+
const browser = new AgentBrowser({
|
|
19
|
+
headless: true,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Create an agent with the browser
|
|
23
|
+
const agent = new Agent({
|
|
24
|
+
name: 'web-agent',
|
|
25
|
+
instructions: `You are a web automation assistant.
|
|
26
|
+
Use browser_snapshot to see the page structure,
|
|
27
|
+
then interact with elements using their refs (e.g., @e5).`,
|
|
28
|
+
model: 'openai/gpt-5.4',
|
|
29
|
+
browser,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Use the agent to browse the web
|
|
33
|
+
const result = await agent.generate('Go to example.com and click the first link');
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
const browser = new AgentBrowser({
|
|
40
|
+
// Run headless (default: true)
|
|
41
|
+
headless: true,
|
|
42
|
+
|
|
43
|
+
// Viewport dimensions
|
|
44
|
+
viewport: { width: 1280, height: 720 },
|
|
45
|
+
|
|
46
|
+
// Default timeout for operations in ms (default: 30000)
|
|
47
|
+
timeout: 30000,
|
|
48
|
+
|
|
49
|
+
// CDP URL for connecting to existing browser
|
|
50
|
+
cdpUrl: 'ws://localhost:9222',
|
|
51
|
+
|
|
52
|
+
// Browser instance scope
|
|
53
|
+
// Default: 'thread' for local launch, 'shared' when cdpUrl is provided
|
|
54
|
+
// 'thread': Each thread gets its own browser
|
|
55
|
+
// 'shared': All threads share one browser
|
|
56
|
+
scope: 'thread',
|
|
57
|
+
|
|
58
|
+
// Screencast settings for Studio
|
|
59
|
+
screencast: {
|
|
60
|
+
enabled: true,
|
|
61
|
+
format: 'jpeg',
|
|
62
|
+
quality: 80,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Tools
|
|
68
|
+
|
|
69
|
+
AgentBrowser exposes 15 deterministic tools using accessibility tree refs:
|
|
70
|
+
|
|
71
|
+
### Core Tools
|
|
72
|
+
|
|
73
|
+
- **browser_goto** - Navigate to a URL
|
|
74
|
+
- **browser_snapshot** - Get accessibility tree with element refs (@e1, @e2, etc.)
|
|
75
|
+
- **browser_click** - Click an element by ref
|
|
76
|
+
- **browser_type** - Type text into an element
|
|
77
|
+
- **browser_press** - Press keyboard keys
|
|
78
|
+
- **browser_select** - Select option from dropdown
|
|
79
|
+
- **browser_scroll** - Scroll the page or element
|
|
80
|
+
- **browser_close** - Close the browser
|
|
81
|
+
|
|
82
|
+
### Extended Tools
|
|
83
|
+
|
|
84
|
+
- **browser_hover** - Hover over an element
|
|
85
|
+
- **browser_back** - Go back in browser history
|
|
86
|
+
- **browser_dialog** - Handle browser dialogs (alert, confirm, prompt)
|
|
87
|
+
- **browser_wait** - Wait for element state changes
|
|
88
|
+
- **browser_tabs** - Manage browser tabs (list, new, switch, close)
|
|
89
|
+
- **browser_drag** - Drag and drop elements
|
|
90
|
+
|
|
91
|
+
### Escape Hatch
|
|
92
|
+
|
|
93
|
+
- **browser_evaluate** - Execute JavaScript in the page context
|
|
94
|
+
|
|
95
|
+
## How Refs Work
|
|
96
|
+
|
|
97
|
+
AgentBrowser uses accessibility tree refs for precise element targeting:
|
|
98
|
+
|
|
99
|
+
1. Call `browser_snapshot` to get the page structure with refs
|
|
100
|
+
2. Find the element you want to interact with
|
|
101
|
+
3. Use its ref with other tools
|
|
102
|
+
|
|
103
|
+
```text
|
|
104
|
+
[document] Example Page
|
|
105
|
+
[banner]
|
|
106
|
+
[link @e1] Home
|
|
107
|
+
[link @e2] About
|
|
108
|
+
[main]
|
|
109
|
+
[textbox @e3] Search...
|
|
110
|
+
[button @e4] Submit
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
// Type in the search box
|
|
115
|
+
{ tool: "browser_type", input: { ref: "@e3", text: "mastra" } }
|
|
116
|
+
|
|
117
|
+
// Click submit
|
|
118
|
+
{ tool: "browser_click", input: { ref: "@e4" } }
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Comparison with StagehandBrowser
|
|
122
|
+
|
|
123
|
+
| Feature | AgentBrowser | StagehandBrowser |
|
|
124
|
+
| ----------- | ------------------------ | ---------------------------- |
|
|
125
|
+
| Approach | Deterministic refs (@e1) | Natural language |
|
|
126
|
+
| Token cost | Low | Higher (LLM calls) |
|
|
127
|
+
| Speed | Fast | Slower |
|
|
128
|
+
| Reliability | High (exact refs) | Variable (AI interpretation) |
|
|
129
|
+
| Best for | Structured workflows | Unknown/dynamic pages |
|
|
130
|
+
|
|
131
|
+
## Documentation
|
|
132
|
+
|
|
133
|
+
- [agent-browser guide](https://mastra.ai/docs/browser/agent-browser) - Usage guide
|
|
134
|
+
- [AgentBrowser reference](https://mastra.ai/reference/browser/agent-browser) - API reference
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
Apache-2.0
|