chrometools-mcp 1.0.0 → 1.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 CHANGED
@@ -6,11 +6,15 @@ MCP server for Chrome automation using Puppeteer with persistent browser session
6
6
 
7
7
  - [Installation](#installation)
8
8
  - [Usage](#usage)
9
- - [Available Tools](#available-tools) - **16 Tools Total**
9
+ - [AI Optimization Features](#ai-optimization-features) **NEW**
10
+ - [Scenario Recorder](#scenario-recorder) ⭐ **NEW** - Visual UI-based recording with smart optimization
11
+ - [Available Tools](#available-tools) - **26+ Tools Total**
12
+ - [AI-Powered Tools](#ai-powered-tools) ⭐ **NEW** - smartFindElement, analyzePage, getAllInteractiveElements, findElementsByText
10
13
  - [Core Tools](#1-core-tools) - ping, openBrowser
11
14
  - [Interaction Tools](#2-interaction-tools) - click, type, scrollTo
12
15
  - [Inspection Tools](#3-inspection-tools) - getElement, getComputedCss, getBoxModel, screenshot
13
16
  - [Advanced Tools](#4-advanced-tools) - executeScript, getConsoleLogs, hover, setStyles, setViewport, getViewport, navigateTo
17
+ - [Recorder Tools](#5-recorder-tools) ⭐ **NEW** - enableRecorder, executeScenario, listScenarios, searchScenarios, getScenarioInfo, deleteScenario
14
18
  - [Typical Workflow Example](#typical-workflow-example)
15
19
  - [Tool Usage Tips](#tool-usage-tips)
16
20
  - [Configuration](#configuration)
@@ -40,8 +44,114 @@ Add to your MCP client configuration (e.g., Claude Desktop):
40
44
  }
41
45
  ```
42
46
 
47
+ ## AI Optimization Features
48
+
49
+ ⭐ **NEW**: Dramatically reduce AI agent request cycles with intelligent element finding and page analysis.
50
+
51
+ ### Why This Matters
52
+
53
+ Traditional browser automation with AI requires many trial-and-error cycles:
54
+ ```
55
+ AI: "Find login button"
56
+ → Try selector #1: Not found
57
+ → Try selector #2: Not found
58
+ → Try selector #3: Found! (3 requests, 15-30 seconds)
59
+ ```
60
+
61
+ **With AI optimization:**
62
+ ```
63
+ AI: smartFindElement("login button")
64
+ → Returns ranked candidates with confidence scores (1 request, 2 seconds)
65
+ ```
66
+
67
+ ### Key Features
68
+
69
+ 1. **`smartFindElement`** - Natural language element search with multilingual support
70
+ 2. **`analyzePage`** - Complete page structure in one request (cached)
71
+ 3. **AI Hints** - Automatic context in all tools (page type, available actions, suggestions)
72
+ 4. **Batch helpers** - `getAllInteractiveElements`, `findElementsByText`
73
+
74
+ **Performance:** 3-5x faster, 5-10x fewer requests
75
+
76
+ 📚 [Full AI Optimization Guide](AI_OPTIMIZATION.md)
77
+
78
+ ## Scenario Recorder
79
+
80
+ ⭐ **NEW**: Visual UI-based recorder for creating reusable test scenarios with automatic secret detection.
81
+
82
+ ### Features
83
+
84
+ - **Visual Widget** - Floating recorder UI with compact mode (50x50px minimize button)
85
+ - **Smart Recording** - Captures clicks, typing, navigation with intelligent optimization
86
+ - **Secret Detection** - Auto-detects passwords/emails and stores them securely
87
+ - **Action Optimization** - Combines sequential actions, removes duplicates
88
+ - **Scenario Management** - Save, load, execute, search, and delete scenarios
89
+ - **Dependencies** - Chain scenarios together with dependency resolution
90
+
91
+ ### Quick Start
92
+
93
+ ```javascript
94
+ // 1. Enable recorder UI
95
+ enableRecorder()
96
+
97
+ // 2. Click "Start" in widget, perform actions, click "Stop & Save"
98
+ // 3. Execute saved scenario
99
+ executeScenario({ name: "login_flow", parameters: { email: "user@test.com" } })
100
+ ```
101
+
102
+ 📚 [Full Recorder Guide](RECORDER_QUICKSTART.md) | [Recorder Spec](RECORDER_SPEC.md)
103
+
43
104
  ## Available Tools
44
105
 
106
+ ### AI-Powered Tools
107
+
108
+ #### smartFindElement ⭐
109
+ Find elements using natural language descriptions instead of CSS selectors.
110
+ - **Parameters**:
111
+ - `description` (required): Natural language (e.g., "login button", "email field")
112
+ - `maxResults` (optional): Max candidates to return (default: 5)
113
+ - **Use case**: When you don't know the exact selector
114
+ - **Returns**: Ranked candidates with confidence scores, selectors, and reasoning
115
+ - **Example**:
116
+ ```json
117
+ {
118
+ "description": "submit button",
119
+ "maxResults": 3
120
+ }
121
+ ```
122
+ Returns:
123
+ ```json
124
+ {
125
+ "candidates": [
126
+ { "selector": "button.login-btn", "confidence": 0.95, "text": "Login", "reason": "type=submit, in form, matching keyword" },
127
+ { "selector": "#submit", "confidence": 0.7, "text": "Send", "reason": "submit class" }
128
+ ],
129
+ "hints": { "suggestion": "Use selector: button.login-btn" }
130
+ }
131
+ ```
132
+
133
+ #### analyzePage ⭐
134
+ Get complete page structure in one request. Results are cached per URL.
135
+ - **Parameters**:
136
+ - `refresh` (optional): Force refresh cache (default: false)
137
+ - **Use case**: Understanding page structure before planning actions
138
+ - **Returns**: Complete map of forms, inputs, buttons, links, navigation with selectors
139
+ - **Example**: Returns structured data for all interactive elements on the page
140
+
141
+ #### getAllInteractiveElements
142
+ Get all clickable/fillable elements with their selectors.
143
+ - **Parameters**:
144
+ - `includeHidden` (optional): Include hidden elements (default: false)
145
+ - **Returns**: Array of all interactive elements with selectors and metadata
146
+
147
+ #### findElementsByText
148
+ Find elements by their visible text content.
149
+ - **Parameters**:
150
+ - `text` (required): Text to search for
151
+ - `exact` (optional): Exact match only (default: false)
152
+ - `caseSensitive` (optional): Case sensitive search (default: false)
153
+ - **Returns**: Elements containing the text with their selectors
154
+
45
155
  ### 1. Core Tools
46
156
 
47
157
  #### ping
@@ -167,6 +277,60 @@ Navigate to different URL while keeping browser instance.
167
277
  - **Use case**: Moving between pages in workflow
168
278
  - **Returns**: New page title
169
279
 
280
+ ### 5. Recorder Tools ⭐ NEW
281
+
282
+ #### enableRecorder
283
+ Inject visual recorder UI widget into the current page.
284
+ - **Parameters**: None
285
+ - **Use case**: Start recording user interactions visually
286
+ - **Returns**: Success status
287
+ - **Features**:
288
+ - Floating widget with compact mode (minimize to 50x50px)
289
+ - Visual recording indicator (red pulsing border)
290
+ - Start/Pause/Stop/Stop & Save/Clear controls
291
+ - Real-time action list display
292
+ - Metadata fields (name, description, tags)
293
+
294
+ #### executeScenario
295
+ Execute a previously recorded scenario by name.
296
+ - **Parameters**:
297
+ - `name` (required): Scenario name
298
+ - `parameters` (optional): Runtime parameters (e.g., { email: "user@test.com" })
299
+ - **Use case**: Run automated test scenarios
300
+ - **Returns**: Execution result with success/failure status
301
+ - **Features**:
302
+ - Automatic dependency resolution
303
+ - Secret parameter injection
304
+ - Fallback selector retry logic
305
+
306
+ #### listScenarios
307
+ Get all available scenarios with metadata.
308
+ - **Parameters**: None
309
+ - **Use case**: Browse recorded scenarios
310
+ - **Returns**: Array of scenarios with names, descriptions, tags, timestamps
311
+
312
+ #### searchScenarios
313
+ Search scenarios by text or tags.
314
+ - **Parameters**:
315
+ - `text` (optional): Search in name/description
316
+ - `tags` (optional): Array of tags to filter
317
+ - **Use case**: Find specific scenarios
318
+ - **Returns**: Matching scenarios
319
+
320
+ #### getScenarioInfo
321
+ Get detailed information about a scenario.
322
+ - **Parameters**:
323
+ - `name` (required): Scenario name
324
+ - `includeSecrets` (optional): Include secret values (default: false)
325
+ - **Use case**: Inspect scenario actions and dependencies
326
+ - **Returns**: Full scenario details (actions, metadata, dependencies)
327
+
328
+ #### deleteScenario
329
+ Delete a scenario and its associated secrets.
330
+ - **Parameters**: `name` (required)
331
+ - **Use case**: Clean up unused scenarios
332
+ - **Returns**: Success confirmation
333
+
170
334
  ---
171
335
 
172
336
  ## Typical Workflow Example
@@ -0,0 +1,408 @@
1
+ # Scenario Recorder - Quick Start Guide
2
+
3
+ ## What is the Scenario Recorder?
4
+
5
+ The Scenario Recorder allows you to **visually record browser interactions** and save them as reusable scenarios. Instead of writing selectors manually, you interact with the page normally while the recorder captures all your actions.
6
+
7
+ ## Key Features
8
+
9
+ ✅ **Visual Recording** - Browser UI widget for start/stop/save
10
+ ✅ **9 Action Types** - Click, type, select, scroll, hover, keypress, wait, upload, drag
11
+ ✅ **Smart Secrets** - Auto-detects passwords/emails in auth forms only
12
+ ✅ **Action Optimization** - Combines sequential actions automatically
13
+ ✅ **Dependency Chaining** - Link scenarios together
14
+ ✅ **Retry Logic** - Auto-recovery if selectors fail
15
+
16
+ ## Basic Workflow
17
+
18
+ ### 1. Enable Recorder in Browser
19
+
20
+ ```javascript
21
+ // MCP Tool: enableRecorder
22
+ await enableRecorder()
23
+ ```
24
+
25
+ This injects a floating widget into the page.
26
+
27
+ ### 2. Start Recording
28
+
29
+ Click **"Start"** button in the widget. The widget shows:
30
+ - 🟢 Green dot when recording
31
+ - Action count in real-time
32
+ - Visual highlighting of interactions
33
+
34
+ ### 3. Perform Actions
35
+
36
+ Interact with the page normally:
37
+ - Click buttons/links
38
+ - Fill form fields
39
+ - Select dropdowns
40
+ - Scroll to elements
41
+ - Upload files
42
+ - Press keyboard shortcuts
43
+
44
+ The recorder captures everything!
45
+
46
+ ### 4. Fill Metadata (Optional)
47
+
48
+ Click ⚙️ to expand metadata:
49
+ - **Scenario Name** (required)
50
+ - Description
51
+ - Tags (comma-separated)
52
+
53
+ ### 5. Stop & Save
54
+
55
+ Click **"Stop & Save"** button.
56
+
57
+ The scenario is saved to:
58
+ - `scenarios/<name>.json` - Shareable scenario
59
+ - `secrets/<name>.json` - Private credentials (auto .gitignore)
60
+
61
+ ## Using Recorded Scenarios
62
+
63
+ ### Execute a Scenario
64
+
65
+ ```javascript
66
+ // MCP Tool: executeScenario
67
+ await executeScenario({
68
+ name: "login_flow",
69
+ parameters: {
70
+ email: "user@example.com",
71
+ password: "secret123"
72
+ }
73
+ })
74
+ ```
75
+
76
+ ### List Available Scenarios
77
+
78
+ ```javascript
79
+ // MCP Tool: listScenarios
80
+ await listScenarios()
81
+ // Returns: [{ name, description, tags, dependencies, createdAt, updatedAt }, ...]
82
+ ```
83
+
84
+ ### Search Scenarios
85
+
86
+ ```javascript
87
+ // MCP Tool: searchScenarios
88
+ await searchScenarios({
89
+ text: "checkout",
90
+ tags: ["ecommerce"]
91
+ })
92
+ ```
93
+
94
+ ## Advanced Features
95
+
96
+ ### 1. Dependency Chaining
97
+
98
+ Scenarios can depend on other scenarios:
99
+
100
+ ```json
101
+ {
102
+ "name": "checkout_flow",
103
+ "metadata": {
104
+ "dependencies": [
105
+ {
106
+ "scenario": "login_flow",
107
+ "optional": false,
108
+ "condition": {
109
+ "check": "isAuthenticated",
110
+ "skipIf": true
111
+ }
112
+ }
113
+ ]
114
+ }
115
+ }
116
+ ```
117
+
118
+ When you execute `checkout_flow`, it automatically runs `login_flow` first (if not already authenticated).
119
+
120
+ ### 2. Parameter Substitution
121
+
122
+ Use `{{paramName}}` in recorded values:
123
+
124
+ ```json
125
+ {
126
+ "type": "type",
127
+ "selector": { "value": "input[name='search']" },
128
+ "data": {
129
+ "text": "{{searchQuery}}"
130
+ }
131
+ }
132
+ ```
133
+
134
+ At execution time, provide the parameter:
135
+
136
+ ```javascript
137
+ executeScenario({
138
+ name: "search_products",
139
+ parameters: {
140
+ searchQuery: "laptop"
141
+ }
142
+ })
143
+ ```
144
+
145
+ ### 3. Secret Detection
146
+
147
+ Secrets are **automatically detected** in authentication forms:
148
+
149
+ **✅ Detected as secrets:**
150
+ - Password fields in login/register forms
151
+ - Email fields in login/register forms
152
+ - Phone fields in login/register forms
153
+ - OTP/verification codes
154
+
155
+ **❌ NOT detected as secrets:**
156
+ - Search boxes
157
+ - Comment fields
158
+ - Profile update forms (non-auth)
159
+ - Phone fields in checkout forms
160
+
161
+ Secrets are:
162
+ - Stored separately in `secrets/<name>.json`
163
+ - Automatically .gitignored
164
+ - Masked in UI (shown as ***)
165
+ - Substituted with {{parameter}} in scenarios
166
+
167
+ ### 4. Custom Selects
168
+
169
+ The recorder detects custom select components (React Select, Material UI, etc.) and records them as multi-step actions:
170
+
171
+ ```json
172
+ {
173
+ "type": "select",
174
+ "data": {
175
+ "selectType": "custom",
176
+ "steps": [
177
+ { "action": "click", "selector": ".select-container" },
178
+ { "action": "wait", "duration": 300 },
179
+ { "action": "click", "selector": ".option[data-value='US']" }
180
+ ]
181
+ }
182
+ }
183
+ ```
184
+
185
+ ### 5. Action Optimization
186
+
187
+ After recording, actions are automatically optimized:
188
+
189
+ **Before optimization:**
190
+ ```json
191
+ [
192
+ { "type": "type", "data": { "text": "H" } },
193
+ { "type": "type", "data": { "text": "e" } },
194
+ { "type": "type", "data": { "text": "l" } },
195
+ { "type": "type", "data": { "text": "l" } },
196
+ { "type": "type", "data": { "text": "o" } }
197
+ ]
198
+ ```
199
+
200
+ **After optimization:**
201
+ ```json
202
+ [
203
+ { "type": "type", "data": { "text": "Hello" } }
204
+ ]
205
+ ```
206
+
207
+ Other optimizations:
208
+ - Removes duplicate clicks
209
+ - Merges sequential waits
210
+ - Detects custom select patterns
211
+ - Removes unnecessary scrolls/hovers
212
+
213
+ ## File Structure
214
+
215
+ ```
216
+ your-project/
217
+ ├── scenarios/ # Shareable scenarios (commit to git)
218
+ │ ├── index.json # Scenario metadata index
219
+ │ ├── login_flow.json
220
+ │ └── checkout_flow.json
221
+
222
+ └── secrets/ # Private credentials (auto .gitignore)
223
+ ├── .gitignore # Auto-created
224
+ ├── login_flow.json
225
+ └── checkout_flow.json
226
+ ```
227
+
228
+ ## Example Scenario
229
+
230
+ Here's what a recorded login scenario looks like:
231
+
232
+ ```json
233
+ {
234
+ "name": "login_flow",
235
+ "version": "1.0",
236
+ "createdAt": "2025-01-15T10:30:00.000Z",
237
+ "metadata": {
238
+ "description": "Standard login flow",
239
+ "tags": ["auth", "login"],
240
+ "dependencies": [],
241
+ "parameters": {
242
+ "email": { "type": "string", "required": true },
243
+ "password": { "type": "string", "required": true }
244
+ }
245
+ },
246
+ "chain": [
247
+ {
248
+ "type": "click",
249
+ "selector": { "primary": "a.login-link" },
250
+ "timestamp": 1705320000000,
251
+ "data": { "text": "Login" }
252
+ },
253
+ {
254
+ "type": "type",
255
+ "selector": { "primary": "input[name='email']" },
256
+ "timestamp": 1705320001000,
257
+ "data": { "text": "{{email}}", "isSecret": true }
258
+ },
259
+ {
260
+ "type": "type",
261
+ "selector": { "primary": "input[type='password']" },
262
+ "timestamp": 1705320002000,
263
+ "data": { "text": "{{password}}", "isSecret": true }
264
+ },
265
+ {
266
+ "type": "click",
267
+ "selector": { "primary": "button[type='submit']" },
268
+ "timestamp": 1705320003000,
269
+ "data": { "text": "Sign In" }
270
+ }
271
+ ]
272
+ }
273
+ ```
274
+
275
+ ## Troubleshooting
276
+
277
+ ### Recorder UI Not Visible
278
+
279
+ **Problem:** Widget doesn't appear after calling `enableRecorder()`
280
+
281
+ **Solutions:**
282
+ 1. Check browser console for errors
283
+ 2. Ensure page has finished loading
284
+ 3. Try refreshing page and enabling again
285
+
286
+ ### Selector Fails During Playback
287
+
288
+ **Problem:** "Element not found" error during execution
289
+
290
+ **Solutions:**
291
+ 1. **Automatic:** Executor retries with fallback selectors
292
+ 2. **Automatic:** Executor uses smartFindElement with element text
293
+ 3. **Manual:** Edit scenario JSON and update selector
294
+
295
+ ### Secret Not Detected
296
+
297
+ **Problem:** Password field not marked as secret
298
+
299
+ **Check:**
300
+ 1. Is the field in a `<form>` element?
301
+ 2. Does the form have auth keywords (login/register/reset)?
302
+ 3. Is the field type="password" or has password-related name/id?
303
+
304
+ **Note:** Phone/email in non-auth forms are NOT secrets by design!
305
+
306
+ ### Actions Too Granular
307
+
308
+ **Problem:** Too many small actions recorded
309
+
310
+ **Solution:** Action optimizer runs automatically, but you can also:
311
+ 1. Increase debounce time in recorder settings
312
+ 2. Manually edit scenario JSON after recording
313
+
314
+ ## Best Practices
315
+
316
+ ### 1. Naming Scenarios
317
+
318
+ ✅ Good:
319
+ - `login_flow`
320
+ - `search_products`
321
+ - `checkout_guest`
322
+
323
+ ❌ Bad:
324
+ - `test1`
325
+ - `scenario_2025_01_15`
326
+ - `my_recording`
327
+
328
+ ### 2. Using Tags
329
+
330
+ Group related scenarios:
331
+
332
+ ```javascript
333
+ tags: ["auth", "login"] // Login scenario
334
+ tags: ["auth", "register"] // Register scenario
335
+ tags: ["ecommerce", "checkout"] // Checkout scenario
336
+ tags: ["admin", "users"] // Admin user management
337
+ ```
338
+
339
+ ### 3. Dependency Design
340
+
341
+ **Keep dependencies simple:**
342
+
343
+ ✅ Good:
344
+ ```
345
+ checkout_flow → login_flow
346
+ ```
347
+
348
+ ❌ Bad (deep nesting):
349
+ ```
350
+ scenario_5 → scenario_4 → scenario_3 → scenario_2 → scenario_1
351
+ ```
352
+
353
+ ### 4. Parameter Naming
354
+
355
+ Use clear, descriptive parameter names:
356
+
357
+ ✅ Good:
358
+ - `email`
359
+ - `password`
360
+ - `searchQuery`
361
+ - `productId`
362
+
363
+ ❌ Bad:
364
+ - `param1`
365
+ - `val`
366
+ - `x`
367
+
368
+ ## Performance Tips
369
+
370
+ ### Execution Speed
371
+
372
+ Typical execution times:
373
+ - Simple form fill: **2-5 seconds**
374
+ - Multi-page flow: **10-15 seconds**
375
+ - Complex workflow: **30-60 seconds**
376
+
377
+ ### Optimization
378
+
379
+ 1. **Use dependencies** instead of duplicating actions
380
+ 2. **Combine scenarios** when they're always used together
381
+ 3. **Remove unnecessary waits** from recorded scenarios
382
+ 4. **Use specific selectors** (ID, data-testid) when possible
383
+
384
+ ## API Reference
385
+
386
+ ### MCP Tools for Recorder
387
+
388
+ | Tool | Purpose |
389
+ |------|---------|
390
+ | `enableRecorder()` | Inject recorder widget into page |
391
+ | `executeScenario(name, params)` | Run a scenario with parameters |
392
+ | `listScenarios()` | Get all scenarios |
393
+ | `searchScenarios(query)` | Search by text/tags |
394
+ | `getScenarioInfo(name)` | Get scenario details |
395
+ | `deleteScenario(name)` | Delete a scenario |
396
+ | `importScenario(json)` | Import from JSON |
397
+ | `exportScenario(name)` | Export to JSON |
398
+ | `getStorageStats()` | Get statistics |
399
+ | `validateStorage()` | Check integrity |
400
+
401
+ ## Next Steps
402
+
403
+ 1. **Try recording** a simple login flow
404
+ 2. **Execute the scenario** with different credentials
405
+ 3. **Create dependencies** between scenarios
406
+ 4. **Share scenarios** with your team (commit `scenarios/` directory)
407
+
408
+ For detailed technical information, see [RECORDER_SPEC.md](RECORDER_SPEC.md).