@mastra/browser-viewer 0.0.0

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/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @mastra/browser-viewer
2
+
3
+ Playwright-based browser viewer for Mastra workspaces with CLI provider support.
4
+
5
+ ## Overview
6
+
7
+ `@mastra/browser-viewer` provides `BrowserViewer`, which launches Chrome via Playwright and exposes the CDP URL for CLI tools (agent-browser, browser-use, browse-cli) to connect. This gives you:
8
+
9
+ - **Full screencast support** — Direct page-level CDP sessions
10
+ - **Input injection** — Mouse and keyboard events work correctly
11
+ - **Browser lifecycle control** — Browser starts/stops with the server
12
+ - **CLI flexibility** — Agent uses skills + workspace commands to drive any CLI
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @mastra/browser-viewer
18
+ # or
19
+ pnpm add @mastra/browser-viewer
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ### Basic Setup
25
+
26
+ ```typescript
27
+ import { BrowserViewer } from '@mastra/browser-viewer';
28
+
29
+ const viewer = new BrowserViewer({
30
+ cli: 'agent-browser', // Which CLI the agent will use
31
+ headless: false, // Show browser window
32
+ });
33
+
34
+ // Launch browser
35
+ await viewer.launch();
36
+
37
+ // Get CDP URL for CLIs to connect
38
+ const cdpUrl = await viewer.getCdpUrl();
39
+ console.log(cdpUrl); // ws://127.0.0.1:9222/devtools/browser/...
40
+ ```
41
+
42
+ ### Connect to Existing Browser
43
+
44
+ ```typescript
45
+ import { BrowserViewer } from '@mastra/browser-viewer';
46
+
47
+ const viewer = new BrowserViewer({
48
+ cli: 'agent-browser',
49
+ cdpUrl: 'ws://127.0.0.1:9222/devtools/browser/abc123',
50
+ });
51
+ ```
52
+
53
+ ### With Workspace
54
+
55
+ The CDP URL is automatically injected into CLI commands when used with workspace tools.
56
+
57
+ ```typescript
58
+ import { Workspace, LocalSandbox } from '@mastra/core';
59
+ import { BrowserViewer } from '@mastra/browser-viewer';
60
+
61
+ const workspace = new Workspace({
62
+ sandbox: new LocalSandbox({ cwd: './workspace' }),
63
+ browser: new BrowserViewer({
64
+ cli: 'agent-browser',
65
+ headless: false,
66
+ }),
67
+ });
68
+
69
+ // When agent runs: agent-browser open https://google.com
70
+ // Mastra auto-injects the CDP connection so CLI uses Mastra's browser
71
+ ```
72
+
73
+ ## Configuration
74
+
75
+ | Option | Type | Default | Description |
76
+ | ---------------- | -------------------------------------------------- | ---------- | ------------------------------------------------ |
77
+ | `cli` | `'agent-browser' \| 'browser-use' \| 'browse-cli'` | Required | Which CLI the agent uses |
78
+ | `cdpUrl` | `string` | - | Connect to existing browser instead of launching |
79
+ | `headless` | `boolean` | `false` | Run browser in headless mode |
80
+ | `cdpPort` | `number` | `0` (auto) | Port for Chrome remote debugging |
81
+ | `viewport` | `{ width, height }` | `1280x720` | Browser viewport size |
82
+ | `userDataDir` | `string` | - | Chrome profile directory |
83
+ | `executablePath` | `string` | - | Path to Chrome executable |
84
+
85
+ ## How It Works
86
+
87
+ 1. **BrowserViewer launches Chrome** via Playwright with `--remote-debugging-port`
88
+ 2. **Agent calls CLI commands** via `workspace_execute_command`
89
+ 3. **CDP URL is auto-injected** so CLI connects to Mastra-managed Chrome
90
+ 4. **Screencast streams** directly from page-level CDP sessions
91
+ 5. **Browser closes** when server exits
92
+
93
+ ## Supported CLIs
94
+
95
+ - **agent-browser** — Vercel's browser automation CLI (`--cdp <port>`)
96
+ - **browser-use** — Python-based browser automation (`--cdp-url <url>`)
97
+ - **browse-cli** — Browserbase's Stagehand CLI (`--ws <url>`)
98
+
99
+ ## License
100
+
101
+ Apache-2.0