@bubstack/moe-glass 0.1.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 +29 -0
- package/agents/browser-user.md +105 -0
- package/dist/LICENSE +25 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22517 -0
- package/dist/index.js.map +1 -0
- package/dist/payload.d.ts +214 -0
- package/dist/payload.d.ts.map +1 -0
- package/dist/payload.js +325 -0
- package/dist/payload.js.map +1 -0
- package/package.json +59 -0
- package/skills/browsing/COMMANDLINE-USAGE.md +595 -0
- package/skills/browsing/EXAMPLES.md +717 -0
- package/skills/browsing/README.md +55 -0
- package/skills/browsing/SKILL.md +478 -0
- package/skills/browsing/chrome-ws +1021 -0
- package/skills/browsing/chrome-ws-lib.js +461 -0
- package/skills/browsing/host-override.js +98 -0
- package/skills/browsing/lib/browser-bridge.js +175 -0
- package/skills/browsing/lib/browser-session.js +137 -0
- package/skills/browsing/lib/capture.js +499 -0
- package/skills/browsing/lib/cdp-router.js +72 -0
- package/skills/browsing/lib/cdp-utils.js +18 -0
- package/skills/browsing/lib/chrome-launcher-helpers.js +374 -0
- package/skills/browsing/lib/chrome-process.js +464 -0
- package/skills/browsing/lib/console-logging.js +70 -0
- package/skills/browsing/lib/cookies.js +17 -0
- package/skills/browsing/lib/dialogs-render.js +154 -0
- package/skills/browsing/lib/dialogs-router.js +117 -0
- package/skills/browsing/lib/dialogs.js +254 -0
- package/skills/browsing/lib/element-selector.js +91 -0
- package/skills/browsing/lib/evaluation.js +85 -0
- package/skills/browsing/lib/extraction.js +55 -0
- package/skills/browsing/lib/file-upload.js +56 -0
- package/skills/browsing/lib/html-diff.js +122 -0
- package/skills/browsing/lib/key-definitions.js +149 -0
- package/skills/browsing/lib/keyboard-input.js +288 -0
- package/skills/browsing/lib/mouse.js +423 -0
- package/skills/browsing/lib/navigation.js +272 -0
- package/skills/browsing/lib/page-scripts/dom-summary.js +31 -0
- package/skills/browsing/lib/page-scripts/markdown.js +85 -0
- package/skills/browsing/lib/page-scripts/permission-shim.js +80 -0
- package/skills/browsing/lib/page-session.js +106 -0
- package/skills/browsing/lib/profile-lock.js +179 -0
- package/skills/browsing/lib/screenshot.js +171 -0
- package/skills/browsing/lib/select-option.js +99 -0
- package/skills/browsing/lib/session-state.js +66 -0
- package/skills/browsing/lib/tabs.js +144 -0
- package/skills/browsing/lib/viewport.js +103 -0
- package/skills/browsing/lib/websocket-client.js +162 -0
- package/skills/browsing/package.json +11 -0
- package/skills/browsing/test-chrome-args.js +81 -0
- package/skills/browsing/test-cookies.js +21 -0
- package/skills/browsing/test-e2e.sh +51 -0
- package/skills/browsing/test-extract.sh +17 -0
- package/skills/browsing/test-interact.sh +11 -0
- package/skills/browsing/test-navigate.sh +9 -0
- package/skills/browsing/test-raw.sh +8 -0
- package/skills/browsing/test-tabs.sh +15 -0
- package/skills/browsing/test-viewport.js +27 -0
- package/skills/browsing/test-wait.sh +9 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# chrome-ws
|
|
2
|
+
|
|
3
|
+
Chrome DevTools Protocol CLI - zero dependencies.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
chmod +x chrome-ws
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Test
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
./chrome-ws start # Launch Chrome (auto-detects platform)
|
|
15
|
+
./chrome-ws new "https://example.com" # Create tab
|
|
16
|
+
./chrome-ws navigate 0 "https://example.com"
|
|
17
|
+
./chrome-ws extract 0 "h1" # Extract heading
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Documentation
|
|
21
|
+
|
|
22
|
+
- `SKILL.md` - Complete usage guide
|
|
23
|
+
- `EXAMPLES.md` - Real-world examples
|
|
24
|
+
|
|
25
|
+
## Testing
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
./test-raw.sh # Raw JSON-RPC
|
|
29
|
+
./test-tabs.sh # Tab management
|
|
30
|
+
./test-navigate.sh # Navigation
|
|
31
|
+
./test-interact.sh # Form interaction
|
|
32
|
+
./test-extract.sh # Content extraction
|
|
33
|
+
./test-wait.sh # Wait commands
|
|
34
|
+
./test-e2e.sh # End-to-end workflow
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Requirements
|
|
38
|
+
|
|
39
|
+
- Node.js 16+
|
|
40
|
+
- Chrome with `--remote-debugging-port=9222`
|
|
41
|
+
|
|
42
|
+
## Environment Variables
|
|
43
|
+
|
|
44
|
+
| Variable | Purpose |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `CHROME_WS_BROWSER` | Path to browser executable (overrides auto-detection) |
|
|
47
|
+
| `CHROME_WS_HOST` | Debug host address (default `127.0.0.1`) |
|
|
48
|
+
| `CHROME_WS_PORT` | Debug port (default `9222`) |
|
|
49
|
+
| `CHROME_WS_PROFILE` | Profile name. Default `moe-glass` with auto-disambiguation when contended; set explicitly to share a Chrome across processes. |
|
|
50
|
+
| `CHROME_EXTRA_ARGS` | Whitespace-separated extra flags appended to the Chrome command line. |
|
|
51
|
+
|
|
52
|
+
## Windows Notes
|
|
53
|
+
|
|
54
|
+
- The CLI now binds to `127.0.0.1:9222` by default to avoid name-resolution issues on Windows.
|
|
55
|
+
- Customize the connection via `CHROME_WS_HOST` / `CHROME_WS_PORT` if you forward DevTools elsewhere.
|
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: browsing
|
|
3
|
+
description: Use when you need direct browser control - teaches Chrome DevTools Protocol for controlling existing browser sessions, multi-tab management, form automation, and content extraction via use_browser MCP tool
|
|
4
|
+
allowed-tools: mcp__moe-glass__use_browser
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Browsing with Chrome Direct
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
Control Chrome via DevTools Protocol using the `use_browser` MCP tool. Single unified interface with auto-starting Chrome.
|
|
12
|
+
|
|
13
|
+
**Announce:** "I'm using the browsing skill to control Chrome."
|
|
14
|
+
|
|
15
|
+
## When to Use
|
|
16
|
+
|
|
17
|
+
**Use this when:**
|
|
18
|
+
- Controlling authenticated sessions
|
|
19
|
+
- Managing multiple tabs in running browser
|
|
20
|
+
- Playwright MCP unavailable or excessive
|
|
21
|
+
|
|
22
|
+
**Use Playwright MCP when:**
|
|
23
|
+
- Need fresh browser instances
|
|
24
|
+
- Generating screenshots/PDFs
|
|
25
|
+
- Prefer higher-level abstractions
|
|
26
|
+
|
|
27
|
+
## Auto-Capture
|
|
28
|
+
|
|
29
|
+
Every DOM action (navigate, click, type, select, eval, keyboard_press, hover, drag_drop, double_click, right_click, file_upload) automatically saves:
|
|
30
|
+
- `{prefix}.png` — viewport screenshot
|
|
31
|
+
- `{prefix}.md` — page content as structured markdown
|
|
32
|
+
- `{prefix}.html` — full rendered DOM
|
|
33
|
+
- `{prefix}-console.txt` — browser console messages
|
|
34
|
+
|
|
35
|
+
Files are saved to the session directory with sequential prefixes (001-navigate, 002-click, etc.). You must check these before using extract or screenshot actions.
|
|
36
|
+
|
|
37
|
+
## The use_browser Tool
|
|
38
|
+
|
|
39
|
+
Single MCP tool with action-based interface. Chrome auto-starts on first use.
|
|
40
|
+
|
|
41
|
+
**Parameters:**
|
|
42
|
+
- `action` (required): Operation to perform
|
|
43
|
+
- `selector` (optional): CSS or XPath selector for element operations
|
|
44
|
+
- `payload` (optional): Action-specific data (string or object)
|
|
45
|
+
- `timeout` (optional): Timeout in ms for await operations (default: 5000)
|
|
46
|
+
|
|
47
|
+
**Active tab**: Every action operates on the current `activeTab`. Use `switch_tab` to change it.
|
|
48
|
+
|
|
49
|
+
## Actions Reference
|
|
50
|
+
|
|
51
|
+
### Navigation
|
|
52
|
+
- **navigate**: Navigate to URL
|
|
53
|
+
- `payload`: URL string
|
|
54
|
+
- Example: `{action: "navigate", payload: "https://example.com"}`
|
|
55
|
+
|
|
56
|
+
- **await_element**: Wait for element to appear
|
|
57
|
+
- `selector`: CSS selector
|
|
58
|
+
- `timeout`: Max wait time in ms
|
|
59
|
+
- Example: `{action: "await_element", selector: ".loaded", timeout: 10000}`
|
|
60
|
+
|
|
61
|
+
- **await_text**: Wait for text to appear
|
|
62
|
+
- `payload`: Text to wait for
|
|
63
|
+
- Example: `{action: "await_text", payload: "Welcome"}`
|
|
64
|
+
|
|
65
|
+
### Interaction
|
|
66
|
+
- **click**: Click element
|
|
67
|
+
- `selector`: CSS selector
|
|
68
|
+
- Example: `{action: "click", selector: "button.submit"}`
|
|
69
|
+
|
|
70
|
+
- **type**: Text input
|
|
71
|
+
- `selector`: Optional — clicks to focus first
|
|
72
|
+
- `payload`: Text to type (`\t`=Tab, `\n`=Enter)
|
|
73
|
+
- Example: `{action: "type", selector: "#email", payload: "user@example.com"}`
|
|
74
|
+
|
|
75
|
+
- **double_click**: Double-click element (fires dblclick event)
|
|
76
|
+
- `selector`: CSS selector
|
|
77
|
+
- Example: `{action: "double_click", selector: ".item"}`
|
|
78
|
+
|
|
79
|
+
- **right_click**: Right-click element (fires contextmenu event)
|
|
80
|
+
- `selector`: CSS selector
|
|
81
|
+
- Example: `{action: "right_click", selector: ".row"}`
|
|
82
|
+
|
|
83
|
+
- **select**: Select dropdown option
|
|
84
|
+
- `selector`: CSS selector
|
|
85
|
+
- `payload`: Option value(s)
|
|
86
|
+
- Example: `{action: "select", selector: "select[name=state]", payload: "CA"}`
|
|
87
|
+
|
|
88
|
+
- **keyboard_press**: Press special keys (Tab, Enter, Escape, Arrow keys, F1-F12)
|
|
89
|
+
- `payload`: Key name (string) or `{"key": "Tab", "modifiers": {"shift": true, "ctrl": false, "alt": false, "meta": false}}`
|
|
90
|
+
- Example: `{action: "keyboard_press", payload: "Tab"}`
|
|
91
|
+
- Example with modifiers: `{action: "keyboard_press", payload: {"key": "Tab", "modifiers": {"shift": true}}}`
|
|
92
|
+
|
|
93
|
+
### Mouse Actions (CDP-Level)
|
|
94
|
+
These use CDP Input.dispatchMouseEvent, bypassing synthetic event restrictions.
|
|
95
|
+
|
|
96
|
+
- **hover**: Move mouse over element (CSS :hover, tooltips, menus)
|
|
97
|
+
- `selector`: CSS selector
|
|
98
|
+
- Example: `{action: "hover", selector: ".menu-trigger"}`
|
|
99
|
+
|
|
100
|
+
- **drag_drop**: Drag element to target (native drag-and-drop via CDP)
|
|
101
|
+
- `selector`: Source element
|
|
102
|
+
- `payload`: Target selector or JSON coordinates `{"x":N,"y":N}`
|
|
103
|
+
- Example: `{action: "drag_drop", selector: ".card", payload: ".column-2"}`
|
|
104
|
+
|
|
105
|
+
- **mouse_move**: Move mouse to coordinates
|
|
106
|
+
- `payload`: JSON `{"x":N,"y":N}` (optional: `steps`, `fromX`, `fromY` for smooth movement)
|
|
107
|
+
- Example: `{action: "mouse_move", payload: "{\"x\":100,\"y\":200}"}`
|
|
108
|
+
|
|
109
|
+
- **scroll**: Scroll via mouse wheel events
|
|
110
|
+
- `payload`: Direction (up/down/left/right) or JSON `{"deltaX":N,"deltaY":N}`
|
|
111
|
+
- `selector`: Optional — scroll within element
|
|
112
|
+
- Example: `{action: "scroll", payload: "down"}`
|
|
113
|
+
|
|
114
|
+
### File Upload
|
|
115
|
+
- **file_upload**: Set files on input[type=file] elements (can't be done via JavaScript)
|
|
116
|
+
- `selector`: File input element
|
|
117
|
+
- `payload`: File path or JSON `{"files":["/path/a.pdf","/path/b.jpg"]}`
|
|
118
|
+
- Example: `{action: "file_upload", selector: "#upload", payload: "/tmp/doc.pdf"}`
|
|
119
|
+
|
|
120
|
+
### Extraction
|
|
121
|
+
- **extract**: Get page content
|
|
122
|
+
- `payload`: Format ('markdown'|'text'|'html')
|
|
123
|
+
- `selector`: Optional - limit to element
|
|
124
|
+
- Example: `{action: "extract", payload: "markdown"}`
|
|
125
|
+
- Example: `{action: "extract", payload: "text", selector: "h1"}`
|
|
126
|
+
|
|
127
|
+
- **attr**: Get element attribute
|
|
128
|
+
- `selector`: CSS selector
|
|
129
|
+
- `payload`: Attribute name
|
|
130
|
+
- Example: `{action: "attr", selector: "a.download", payload: "href"}`
|
|
131
|
+
|
|
132
|
+
- **eval**: Execute JavaScript
|
|
133
|
+
- `payload`: JavaScript code
|
|
134
|
+
- Example: `{action: "eval", payload: "document.title"}`
|
|
135
|
+
|
|
136
|
+
### Export
|
|
137
|
+
- **screenshot**: Capture screenshot of a specific element
|
|
138
|
+
- `payload`: Filename
|
|
139
|
+
- `selector`: Optional - screenshot specific element
|
|
140
|
+
- Viewport screenshots are auto-captured after every DOM action. Use this only when you need a specific element.
|
|
141
|
+
- Example: `{action: "screenshot", payload: "/tmp/chart.png", selector: ".chart"}`
|
|
142
|
+
|
|
143
|
+
### Tab Management
|
|
144
|
+
- **list_tabs**: List all open tabs
|
|
145
|
+
- Example: `{action: "list_tabs"}`
|
|
146
|
+
|
|
147
|
+
- **new_tab**: Create new tab
|
|
148
|
+
- Example: `{action: "new_tab"}`
|
|
149
|
+
|
|
150
|
+
- **close_tab**: Close the active tab
|
|
151
|
+
- Example: `{action: "close_tab"}`
|
|
152
|
+
|
|
153
|
+
- **switch_tab**: Switch the active tab (sticky — stays until changed)
|
|
154
|
+
- `payload`: Tab index (number), URL substring, or title substring
|
|
155
|
+
- Example: `{action: "switch_tab", payload: 1}` (by index)
|
|
156
|
+
- Example: `{action: "switch_tab", payload: "example.com"}` (by URL substring)
|
|
157
|
+
- Example: `{action: "switch_tab", payload: "GitHub"}` (by title substring)
|
|
158
|
+
|
|
159
|
+
### Browser Mode Control
|
|
160
|
+
- **show_browser**: Make browser window visible (headed mode)
|
|
161
|
+
- Example: `{action: "show_browser"}`
|
|
162
|
+
- ⚠️ **WARNING**: Restarts Chrome, reloads pages via GET, loses POST state
|
|
163
|
+
|
|
164
|
+
- **hide_browser**: Switch to headless mode (invisible browser)
|
|
165
|
+
- Example: `{action: "hide_browser"}`
|
|
166
|
+
- ⚠️ **WARNING**: Restarts Chrome, reloads pages via GET, loses POST state
|
|
167
|
+
|
|
168
|
+
- **browser_mode**: Check current browser mode, port, and profile
|
|
169
|
+
- Example: `{action: "browser_mode"}`
|
|
170
|
+
- Returns: `{"headless": true|false, "mode": "headless"|"headed", "running": true|false, "port": 9222, "profile": "name", "profileDir": "/path"}`
|
|
171
|
+
|
|
172
|
+
### Profile Management
|
|
173
|
+
- **set_profile**: Change Chrome profile (must kill Chrome first)
|
|
174
|
+
- Example: `{action: "set_profile", "payload": "browser-user"}`
|
|
175
|
+
- ⚠️ **WARNING**: Chrome must be stopped first
|
|
176
|
+
- **Side effect**: marks the profile as explicit, opting out of auto-disambiguation (see below)
|
|
177
|
+
|
|
178
|
+
- **get_profile**: Get current profile name and directory
|
|
179
|
+
- Example: `{action: "get_profile"}`
|
|
180
|
+
- Returns: `{"profile": "name", "profileDir": "/path"}`
|
|
181
|
+
|
|
182
|
+
**Default behavior**: Chrome starts in **headless mode** with **"moe-glass" profile** on a **dynamically allocated port** (range 9222-12111). Override the port with `CHROME_WS_PORT`; override the profile with `CHROME_WS_PROFILE`.
|
|
183
|
+
|
|
184
|
+
**Auto-disambiguation across parallel MCPs**:
|
|
185
|
+
When two MCP servers start on the same host with the default profile, the first claims `moe-glass` (port 9222) and later ones silently fall through to `moe-glass-2` (port 9223), `moe-glass-3`, etc. Each MCP drives its own Chrome with its own profile dir; they don't fight over `activeTab`. The bridge tracks ownership via a lock file at `~/.cache/moe/browser-profiles/<profile>.mcp.lock`; stale locks (dead PIDs) are reclaimed automatically.
|
|
186
|
+
|
|
187
|
+
To opt **out** of disambiguation — e.g., to intentionally share Chrome between a long-lived `chrome-ws` CLI session and your MCP — set the profile name explicitly:
|
|
188
|
+
- Env var: `CHROME_WS_PROFILE=my-profile`
|
|
189
|
+
- Or: `{action: "set_profile", payload: "my-profile"}` at runtime
|
|
190
|
+
|
|
191
|
+
An explicit profile name still acquires the lock, but on conflict the bridge **shares** rather than disambiguates — the second process reconnects to the first's Chrome (the original reconnect-on-restart behavior).
|
|
192
|
+
|
|
193
|
+
### Chrome Lifecycle (Recovery)
|
|
194
|
+
- **kill_chrome**: Kill the Chrome process this MCP is driving
|
|
195
|
+
- Example: `{action: "kill_chrome"}`
|
|
196
|
+
- Releases the meta.json; next page action auto-restarts Chrome
|
|
197
|
+
|
|
198
|
+
- **restart_chrome**: kill_chrome + immediate spawn
|
|
199
|
+
- Example: `{action: "restart_chrome"}`
|
|
200
|
+
|
|
201
|
+
**Auto-restart banner**: when the bridge has to spawn a fresh Chrome (because the previous one died or was killed externally — e.g., `kill -9 <pid>` from the shell), the first response after the restart prepends:
|
|
202
|
+
```
|
|
203
|
+
[Chrome auto-restarted; URL reset to about:blank. Re-navigate to continue.]
|
|
204
|
+
```
|
|
205
|
+
Treat this as a signal that your prior URL / tab state is gone — re-navigate before assuming anything about the current page.
|
|
206
|
+
|
|
207
|
+
### Console Logging
|
|
208
|
+
Capture browser console output for the active tab. Buffer is keyed by the page session's `sessionId`, so it survives `close_tab`/`new_tab` ordering quirks. Levels: `log`, `info`, `warn`, `error`.
|
|
209
|
+
|
|
210
|
+
- **enable_console_logging**: Start capturing
|
|
211
|
+
- Example: `{action: "enable_console_logging"}`
|
|
212
|
+
|
|
213
|
+
- **get_console_messages**: Read captured messages
|
|
214
|
+
- All: `{action: "get_console_messages"}`
|
|
215
|
+
- Since timestamp (epoch ms): `{action: "get_console_messages", payload: {since: 1716000000000}}`
|
|
216
|
+
- Returns: array of `{timestamp, level, text}` entries
|
|
217
|
+
|
|
218
|
+
- **clear_console_messages**: Reset the buffer
|
|
219
|
+
- Example: `{action: "clear_console_messages"}`
|
|
220
|
+
|
|
221
|
+
### Dialog Handling
|
|
222
|
+
Native dialogs (JS alert/confirm/prompt, beforeunload, HTTP basic-auth, permission prompts, device choosers) pause the page. While a dialog is open, page-targeted actions (`extract`, `click`, `eval`, etc.) return a refusal whose text contains `Page is behind a dialog` and lists the available `dialog::*` selectors.
|
|
223
|
+
|
|
224
|
+
When a dialog fires **during** a `navigate` (typical for HTTP basic-auth), `navigate` itself throws with the dialog grammar in the message — you don't have to issue a separate page-targeted call to discover the dialog.
|
|
225
|
+
|
|
226
|
+
Handle dialogs by clicking/typing a `dialog::*` selector:
|
|
227
|
+
- `{action: "click", selector: "dialog::accept"}` — accept JS alert/confirm/prompt, beforeunload, permission grant
|
|
228
|
+
- `{action: "click", selector: "dialog::dismiss"}` — dismiss / cancel / deny
|
|
229
|
+
- `{action: "type", selector: "dialog::prompt", payload: "text"}` then accept — respond to JS prompt
|
|
230
|
+
- `{action: "type", selector: "dialog::username", payload: "alice"}` + `{action: "type", selector: "dialog::password", payload: "secret"}` + `{action: "click", selector: "dialog::accept"}` — HTTP basic-auth
|
|
231
|
+
- `{action: "click", selector: "dialog::device[id=\"<deviceId>\"]"}` — pick a WebUSB/Bluetooth/Serial/HID device
|
|
232
|
+
|
|
233
|
+
**Critical caveats when toggling modes**:
|
|
234
|
+
1. **Chrome must restart** - Cannot switch headless/headed mode on running Chrome
|
|
235
|
+
2. **Pages reload via GET** - All open tabs are reopened with GET requests
|
|
236
|
+
3. **POST state is lost** - Form submissions, POST results, and POST-based navigation will be lost
|
|
237
|
+
4. **Session state is lost** - Any client-side state (JavaScript variables, etc.) is cleared
|
|
238
|
+
5. **Cookies/auth may persist** - Uses same user data directory, so logged-in sessions may survive
|
|
239
|
+
|
|
240
|
+
**When to use headed mode**:
|
|
241
|
+
- Debugging visual rendering issues
|
|
242
|
+
- Demonstrating browser behavior to user
|
|
243
|
+
- Testing features that only work with visible browser
|
|
244
|
+
- Debugging issues that don't reproduce in headless mode
|
|
245
|
+
|
|
246
|
+
**When to stay in headless mode** (default):
|
|
247
|
+
- All other cases - faster, cleaner, less intrusive
|
|
248
|
+
- Screenshots work perfectly in headless mode
|
|
249
|
+
- Most automation works identically in both modes
|
|
250
|
+
|
|
251
|
+
**Profile management**:
|
|
252
|
+
Profiles store persistent browser data (cookies, localStorage, extensions, auth sessions).
|
|
253
|
+
|
|
254
|
+
**Profile locations**:
|
|
255
|
+
- macOS: `~/Library/Caches/moe/browser-profiles/{name}/`
|
|
256
|
+
- Linux: `~/.cache/moe/browser-profiles/{name}/`
|
|
257
|
+
- Windows: `%LOCALAPPDATA%/moe/browser-profiles/{name}/`
|
|
258
|
+
|
|
259
|
+
**When to use separate profiles**:
|
|
260
|
+
- **Default profile ("moe-glass")**: General automation, shared sessions
|
|
261
|
+
- **Agent-specific profiles**: Isolate different agents' browser state
|
|
262
|
+
- Example: browser-user agent uses "browser-user" profile
|
|
263
|
+
- **Task-specific profiles**: Testing with different user contexts
|
|
264
|
+
- Example: "test-logged-in" vs "test-logged-out"
|
|
265
|
+
|
|
266
|
+
**Profile data persists across**:
|
|
267
|
+
- Chrome restarts
|
|
268
|
+
- Mode toggles (headless ↔ headed)
|
|
269
|
+
- System reboots (data is in cache directory)
|
|
270
|
+
|
|
271
|
+
**To use a different profile**:
|
|
272
|
+
1. Kill Chrome if running: `await chromeLib.killChrome()`
|
|
273
|
+
2. Set profile: `{action: "set_profile", "payload": "my-profile"}`
|
|
274
|
+
3. Start Chrome: Next navigate/action will use new profile
|
|
275
|
+
|
|
276
|
+
## Quick Start Pattern
|
|
277
|
+
|
|
278
|
+
```
|
|
279
|
+
Navigate and extract:
|
|
280
|
+
{action: "navigate", payload: "https://example.com"}
|
|
281
|
+
{action: "await_element", selector: "h1"}
|
|
282
|
+
{action: "extract", payload: "text", selector: "h1"}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Common Patterns
|
|
286
|
+
|
|
287
|
+
### Fill and Submit Form
|
|
288
|
+
```
|
|
289
|
+
{action: "navigate", payload: "https://example.com/login"}
|
|
290
|
+
{action: "await_element", selector: "input[name=email]"}
|
|
291
|
+
{action: "type", selector: "input[name=email]", payload: "user@example.com"}
|
|
292
|
+
{action: "type", selector: "input[name=password]", payload: "pass123"}
|
|
293
|
+
{action: "keyboard_press", payload: "Enter"}
|
|
294
|
+
{action: "await_text", payload: "Welcome"}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Uses `keyboard_press` to submit the form.
|
|
298
|
+
|
|
299
|
+
### Multi-Tab Workflow
|
|
300
|
+
```
|
|
301
|
+
{action: "list_tabs"}
|
|
302
|
+
{action: "switch_tab", payload: 2}
|
|
303
|
+
{action: "click", selector: "a.email"}
|
|
304
|
+
{action: "await_element", selector: ".content"}
|
|
305
|
+
{action: "extract", payload: "text", selector: ".amount"}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Dynamic Content
|
|
309
|
+
```
|
|
310
|
+
{action: "navigate", payload: "https://example.com"}
|
|
311
|
+
{action: "type", selector: "input[name=q]", payload: "query"}
|
|
312
|
+
{action: "click", selector: "button.search"}
|
|
313
|
+
{action: "await_element", selector: ".results"}
|
|
314
|
+
{action: "extract", payload: "text", selector: ".result-title"}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Get Link Attribute
|
|
318
|
+
```
|
|
319
|
+
{action: "navigate", payload: "https://example.com"}
|
|
320
|
+
{action: "await_element", selector: "a.download"}
|
|
321
|
+
{action: "attr", selector: "a.download", payload: "href"}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Execute JavaScript
|
|
325
|
+
```
|
|
326
|
+
{action: "eval", payload: "document.querySelectorAll('a').length"}
|
|
327
|
+
{action: "eval", payload: "Array.from(document.querySelectorAll('a')).map(a => a.href)"}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Resize Viewport (Responsive Testing)
|
|
331
|
+
Use `eval` to resize the browser window for testing responsive layouts:
|
|
332
|
+
```
|
|
333
|
+
{action: "eval", payload: "window.resizeTo(375, 812); 'Resized to mobile'"}
|
|
334
|
+
{action: "eval", payload: "window.resizeTo(768, 1024); 'Resized to tablet'"}
|
|
335
|
+
{action: "eval", payload: "window.resizeTo(1920, 1080); 'Resized to desktop'"}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
**Note**: This resizes the window, not device emulation. It won't change:
|
|
339
|
+
- Device pixel ratio (retina displays)
|
|
340
|
+
- Touch events
|
|
341
|
+
- User-Agent string
|
|
342
|
+
|
|
343
|
+
For most responsive testing, window resize is sufficient.
|
|
344
|
+
|
|
345
|
+
### Clear Cookies
|
|
346
|
+
Use `eval` to clear cookies accessible to JavaScript:
|
|
347
|
+
```
|
|
348
|
+
{action: "eval", payload: "document.cookie.split(';').forEach(c => { document.cookie = c.trim().split('=')[0] + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/'; }); 'Cookies cleared'"}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
**Note**: This clears cookies accessible to JavaScript. It won't clear:
|
|
352
|
+
- httpOnly cookies (server-side only)
|
|
353
|
+
- Cookies from other domains
|
|
354
|
+
|
|
355
|
+
For most logout/reset scenarios, this is sufficient.
|
|
356
|
+
|
|
357
|
+
### Scroll Page
|
|
358
|
+
```
|
|
359
|
+
{action: "scroll", payload: "down"}
|
|
360
|
+
{action: "scroll", payload: "up"}
|
|
361
|
+
{action: "scroll", selector: ".container", payload: "{\"deltaX\":0,\"deltaY\":500}"}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
Uses real mouse wheel events (vs `eval` + `scrollTo` which bot detectors flag).
|
|
365
|
+
|
|
366
|
+
## Tips
|
|
367
|
+
|
|
368
|
+
**Always wait before interaction:**
|
|
369
|
+
Don't click or fill immediately after navigate - pages need time to load.
|
|
370
|
+
|
|
371
|
+
```
|
|
372
|
+
// BAD - might fail if page slow
|
|
373
|
+
{action: "navigate", payload: "https://example.com"}
|
|
374
|
+
{action: "click", selector: "button"} // May fail!
|
|
375
|
+
|
|
376
|
+
// GOOD - wait first
|
|
377
|
+
{action: "navigate", payload: "https://example.com"}
|
|
378
|
+
{action: "await_element", selector: "button"}
|
|
379
|
+
{action: "click", selector: "button"}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**Use specific selectors:**
|
|
383
|
+
Avoid generic selectors that match multiple elements.
|
|
384
|
+
|
|
385
|
+
```
|
|
386
|
+
// BAD - matches first button
|
|
387
|
+
{action: "click", selector: "button"}
|
|
388
|
+
|
|
389
|
+
// GOOD - specific
|
|
390
|
+
{action: "click", selector: "button[type=submit]"}
|
|
391
|
+
{action: "click", selector: "#login-button"}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
**Submit forms:**
|
|
395
|
+
Use `keyboard_press` with Enter after `type`, or append `\n` to the payload.
|
|
396
|
+
|
|
397
|
+
```
|
|
398
|
+
{action: "type", selector: "#search", payload: "query"}
|
|
399
|
+
{action: "keyboard_press", payload: "Enter"}
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
**Check content first:**
|
|
403
|
+
Extract page content to verify selectors before building workflow.
|
|
404
|
+
|
|
405
|
+
```
|
|
406
|
+
{action: "extract", payload: "html"}
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
## Troubleshooting
|
|
410
|
+
|
|
411
|
+
**Element not found:**
|
|
412
|
+
- Use `await_element` before interaction
|
|
413
|
+
- Verify selector with `extract` action using 'html' format
|
|
414
|
+
|
|
415
|
+
**Timeout errors:**
|
|
416
|
+
- Increase timeout: `{timeout: 30000}` for slow pages
|
|
417
|
+
- Wait for specific element instead of text
|
|
418
|
+
|
|
419
|
+
**Wrong tab active:**
|
|
420
|
+
- Use `list_tabs` to see all open tabs
|
|
421
|
+
- Use `switch_tab` with a URL or title substring to reliably switch tabs
|
|
422
|
+
- Tab indices shift when tabs close — prefer URL/title-based switching
|
|
423
|
+
|
|
424
|
+
**eval returns `[object Object]`:**
|
|
425
|
+
- Use `JSON.stringify()` for complex objects: `{action: "eval", payload: "JSON.stringify({name: 'test'})"}`
|
|
426
|
+
- For async functions: `{action: "eval", payload: "JSON.stringify(await yourAsyncFunction())"}`
|
|
427
|
+
|
|
428
|
+
## Test Automation (Advanced)
|
|
429
|
+
|
|
430
|
+
<details>
|
|
431
|
+
<summary>Click to expand test automation guidance</summary>
|
|
432
|
+
|
|
433
|
+
When building test automation, you have two approaches:
|
|
434
|
+
|
|
435
|
+
### Approach 1: use_browser MCP (Simple Tests)
|
|
436
|
+
Best for: Single-step tests, direct Claude control during conversation
|
|
437
|
+
|
|
438
|
+
```json
|
|
439
|
+
{"action": "navigate", "payload": "https://app.com"}
|
|
440
|
+
{"action": "click", "selector": "#test-button"}
|
|
441
|
+
{"action": "eval", "payload": "JSON.stringify({passed: document.querySelector('.success') !== null})"}
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
### Approach 2: chrome-ws CLI (Complex Tests)
|
|
445
|
+
Best for: Multi-step test suites, standalone automation scripts
|
|
446
|
+
|
|
447
|
+
**Key insight**: `chrome-ws` is the reference implementation showing proper Chrome DevTools Protocol usage. When `use_browser` doesn't work as expected, examine how `chrome-ws` handles the same operation.
|
|
448
|
+
|
|
449
|
+
```bash
|
|
450
|
+
# Example: Automated form testing
|
|
451
|
+
./chrome-ws navigate 0 "https://app.com/form"
|
|
452
|
+
./chrome-ws fill 0 "#email" "test@example.com"
|
|
453
|
+
./chrome-ws click 0 "button[type=submit]"
|
|
454
|
+
./chrome-ws wait-text 0 "Success"
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### When use_browser Fails
|
|
458
|
+
1. **Check chrome-ws source code** - It shows the correct CDP pattern
|
|
459
|
+
2. **Use chrome-ws to verify** - Test the same operation via CLI
|
|
460
|
+
3. **Adapt the pattern** - Apply the working CDP approach to use_browser
|
|
461
|
+
|
|
462
|
+
### Common Test Automation Patterns
|
|
463
|
+
- **Form validation**: Fill forms, check error states
|
|
464
|
+
- **UI state testing**: Click elements, verify DOM changes
|
|
465
|
+
- **Performance testing**: Measure load times, capture metrics
|
|
466
|
+
- **Screenshot comparison**: Capture before/after states
|
|
467
|
+
|
|
468
|
+
</details>
|
|
469
|
+
|
|
470
|
+
## Advanced Usage
|
|
471
|
+
|
|
472
|
+
For command-line usage outside Claude Code, see [COMMANDLINE-USAGE.md](COMMANDLINE-USAGE.md).
|
|
473
|
+
|
|
474
|
+
For detailed examples, see [EXAMPLES.md](EXAMPLES.md).
|
|
475
|
+
|
|
476
|
+
## Protocol Reference
|
|
477
|
+
|
|
478
|
+
Full CDP documentation: https://chromedevtools.github.io/devtools-protocol/
|