chrome-cdp-cli 1.2.2 â 1.3.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 +430 -45
- package/dist/cli/CLIApplication.js +9 -0
- package/dist/cli/CommandRouter.js +12 -1
- package/dist/handlers/ClickHandler.js +241 -0
- package/dist/handlers/DragHandler.js +267 -0
- package/dist/handlers/FillFormHandler.js +245 -0
- package/dist/handlers/FillHandler.js +354 -0
- package/dist/handlers/HandleDialogHandler.js +197 -0
- package/dist/handlers/HoverHandler.js +268 -0
- package/dist/handlers/InstallClaudeSkillHandler.js +706 -58
- package/dist/handlers/InstallCursorCommandHandler.js +208 -74
- package/dist/handlers/PressKeyHandler.js +337 -0
- package/dist/handlers/TakeSnapshotHandler.js +104 -32
- package/dist/handlers/UploadFileHandler.js +325 -0
- package/dist/handlers/WaitForHandler.js +331 -0
- package/dist/handlers/index.js +9 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
# Chrome DevTools CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Built for LLMs - Eval-First Browser Automation**
|
|
4
|
+
|
|
5
|
+
A command-line tool designed specifically for Large Language Models (LLMs) and AI-assisted development. Controls Chrome browser via Chrome DevTools Protocol (CDP) with an **eval-first design philosophy** - most automation tasks use JavaScript execution because LLMs excel at writing and validating scripts quickly.
|
|
6
|
+
|
|
7
|
+
**Why eval-first?** LLMs are exceptional at writing JavaScript. This tool leverages that strength by using `eval` for most operations, enabling AI assistants (Claude, Cursor, etc.) to write automation scripts instantly and test them in real-time. Includes built-in IDE integrations: install Cursor commands and Claude skills directly.
|
|
8
|
+
|
|
9
|
+
## đ Built for LLMs - Eval-First Design Philosophy
|
|
10
|
+
|
|
11
|
+
**This tool is specifically designed for Large Language Models (LLMs) and AI-assisted development.**
|
|
12
|
+
|
|
13
|
+
### Why Most Commands Use Eval
|
|
14
|
+
|
|
15
|
+
**The core design principle:** Most browser automation tasks are accomplished through the `eval` command rather than dedicated CLI commands. This is intentional and optimized for LLM workflows:
|
|
16
|
+
|
|
17
|
+
1. **đ§ LLMs Excel at JavaScript**: Large Language Models are exceptionally good at writing JavaScript code. They can generate complex automation scripts, handle async operations, and adapt to different scenarios - all in JavaScript.
|
|
18
|
+
|
|
19
|
+
2. **⥠Rapid Script Validation**: LLMs can write a script, test it immediately with `eval`, see the results, and refine it in seconds. This iterative loop is where LLMs shine.
|
|
20
|
+
|
|
21
|
+
3. **đ Maximum Flexibility**: Instead of waiting for specific commands to be implemented, LLMs can accomplish any browser task through JavaScript execution. Need to click an element? `document.querySelector('#btn').click()`. Need to wait for content? `await new Promise(...)`. Need complex data extraction? Just write the JavaScript.
|
|
22
|
+
|
|
23
|
+
4. **đŻ Perfect for AI Workflows**: When you ask Claude or Cursor to automate a browser task, they can write the JavaScript directly - no need to learn complex CLI syntax or wait for feature implementations.
|
|
24
|
+
|
|
25
|
+
### IDE Integration for LLM Workflows
|
|
26
|
+
|
|
27
|
+
**Built-in support for AI development environments:**
|
|
28
|
+
|
|
29
|
+
- **đ„ïž Cursor Commands**: Install with `install-cursor-command` - brings browser automation directly into Cursor's command palette
|
|
30
|
+
- **đ€ Claude Skills**: Install with `install-claude-skill` - enables Claude to use browser automation in conversations
|
|
31
|
+
- **⥠Seamless Integration**: AI assistants can generate automation scripts and execute them instantly through these integrations
|
|
32
|
+
|
|
33
|
+
**Why this matters:** When LLMs are integrated into your IDE, they can write browser automation scripts as part of your development workflow. The eval-first approach means they can accomplish any task without waiting for specific command implementations.
|
|
34
|
+
|
|
35
|
+
### The LLM Advantage
|
|
36
|
+
|
|
37
|
+
- **đ§ Natural Language â JavaScript**: Ask an LLM "click the submit button" â it generates `document.querySelector('#submit').click()`
|
|
38
|
+
- **⥠Instant Testing**: Write, execute, see results, refine - all in seconds
|
|
39
|
+
- **đ Iterative Refinement**: LLMs can adjust scripts based on results immediately
|
|
40
|
+
- **đ Context-Aware**: AI understands your project and can write automation scripts that fit your specific needs
|
|
41
|
+
- **đŻ No Learning Curve**: LLMs already know JavaScript - no need to learn CLI-specific syntax
|
|
4
42
|
|
|
5
43
|
## Implementation Status
|
|
6
44
|
|
|
@@ -11,26 +49,48 @@ A powerful command-line tool for controlling Chrome browser instances via the Ch
|
|
|
11
49
|
- đž **Visual Capture**: Take screenshots and capture complete DOM snapshots with layout information
|
|
12
50
|
- đ **Console Monitoring**: Real-time console message capture with filtering and storage
|
|
13
51
|
- đ **Network Monitoring**: Real-time network request/response monitoring with comprehensive filtering
|
|
52
|
+
- đ±ïž **Element Interaction**: Native click, hover, and form filling commands with CSS selector support
|
|
14
53
|
- đ§ **CLI Interface**: Full command-line interface with argument parsing and routing
|
|
15
54
|
- đ ïž **IDE Integration**: Install Cursor commands and Claude skills with directory validation and --force option
|
|
16
55
|
- đŠ **Build System**: Complete TypeScript build pipeline with testing framework
|
|
17
56
|
|
|
18
|
-
### đ§ Eval
|
|
57
|
+
### đ§ Eval-First Design - LLM-Optimized Features
|
|
19
58
|
|
|
20
|
-
These features
|
|
59
|
+
These features use the `eval` command by design (not as workarounds) - this is the intended approach for LLM-assisted development:
|
|
21
60
|
|
|
22
61
|
- đ **Page Navigation**: `eval "window.location.href = 'https://example.com'"`
|
|
23
|
-
- đ±ïž **Element Interaction**: `eval "document.querySelector('#btn').click()"`
|
|
24
|
-
- đ **Form Filling**: `eval "document.querySelector('#input').value = 'text'"`
|
|
25
|
-
- đ **HTML Content**: `eval "document.documentElement.outerHTML"`
|
|
26
62
|
- đ **Performance Data**: `eval "performance.now()"` or `eval "performance.getEntriesByType('navigation')"`
|
|
27
63
|
- đ± **User Agent**: `eval "navigator.userAgent"`
|
|
28
64
|
- đ **Network Requests**: `eval "fetch('/api').then(r => r.json())"`
|
|
29
65
|
|
|
66
|
+
**Why this design is optimal for LLMs:**
|
|
67
|
+
|
|
68
|
+
1. **LLMs are JavaScript experts**: They can write complex automation scripts instantly
|
|
69
|
+
2. **Rapid validation**: Write â Execute â See Results â Refine - perfect for LLM workflows
|
|
70
|
+
3. **No feature waiting**: LLMs can accomplish any task through JavaScript without waiting for CLI command implementations
|
|
71
|
+
4. **Natural workflow**: When you ask an LLM to automate something, it writes JavaScript - exactly what `eval` executes
|
|
72
|
+
5. **Maximum flexibility**: Any browser API, any complexity level, any scenario - all through JavaScript
|
|
73
|
+
|
|
74
|
+
**This is not a limitation - it's a feature designed specifically for AI-assisted development.**
|
|
75
|
+
|
|
76
|
+
### đŻ IDE Integration - Built for LLM Workflows
|
|
77
|
+
|
|
78
|
+
**Why we support Cursor Commands & Claude Skills:**
|
|
79
|
+
|
|
80
|
+
This tool is designed for LLM-assisted development. The IDE integrations (`install-cursor-command` and `install-claude-skill`) bring browser automation directly into AI-powered development environments:
|
|
81
|
+
|
|
82
|
+
- **đ Seamless LLM Workflow**: AI assistants can write and execute browser automation scripts directly in your IDE
|
|
83
|
+
- **đ§ AI-Native Design**: The eval-first approach means LLMs can accomplish any browser task through JavaScript
|
|
84
|
+
- **⥠Instant Script Validation**: LLMs write JavaScript â execute via eval â see results â refine - all in real-time
|
|
85
|
+
- **đ Context-Aware Automation**: AI understands your project context and can generate relevant automation scripts
|
|
86
|
+
- **đŻ Natural Language â Automation**: Ask "click the submit button" â AI generates `document.querySelector('#submit').click()` â executes instantly
|
|
87
|
+
- **đ€ Perfect for AI Assistants**: Claude and Cursor can use browser automation as part of their toolset
|
|
88
|
+
|
|
89
|
+
**The integration exists because this tool is built for LLMs - the eval-first design and IDE integrations work together to enable AI-powered browser automation.**
|
|
90
|
+
|
|
30
91
|
### âł Not Yet Implemented
|
|
31
92
|
|
|
32
93
|
- đ **Direct Page Management**: Native commands for creating, closing, listing, and selecting tabs
|
|
33
|
-
- đ±ïž **Direct Element Interaction**: Native click, hover, drag, and form filling commands
|
|
34
94
|
- đ **Performance Analysis**: Native performance profiling and metrics collection
|
|
35
95
|
- đ± **Device Emulation**: Native device and network condition simulation
|
|
36
96
|
- đ **Output Formatting**: Advanced JSON/text formatting with quiet/verbose modes
|
|
@@ -41,6 +101,8 @@ These features are not directly implemented but can be achieved using the `eval`
|
|
|
41
101
|
- ⥠**JavaScript Execution**: Execute JavaScript code in browser context with full async support
|
|
42
102
|
- đž **Visual Capture**: Take screenshots and capture HTML content
|
|
43
103
|
- đ **Monitoring**: Monitor console messages and network requests in real-time
|
|
104
|
+
- đ±ïž **Element Interaction**: Native click, hover, and form filling commands with CSS selector support
|
|
105
|
+
- đ **Form Automation**: Single field and batch form filling with comprehensive options
|
|
44
106
|
- đ§ **Flexible Output**: Support for JSON and human-readable text output formats
|
|
45
107
|
- đ§ **Eval Workarounds**: Many advanced features available through JavaScript execution
|
|
46
108
|
|
|
@@ -116,21 +178,29 @@ chrome-cdp-cli screenshot --filename screenshot.png
|
|
|
116
178
|
# Capture DOM snapshot
|
|
117
179
|
chrome-cdp-cli snapshot --filename dom-snapshot.json
|
|
118
180
|
|
|
119
|
-
#
|
|
120
|
-
chrome-cdp-cli
|
|
181
|
+
# Element interactions
|
|
182
|
+
chrome-cdp-cli click "#submit-button"
|
|
183
|
+
chrome-cdp-cli hover ".menu-item"
|
|
184
|
+
chrome-cdp-cli fill "#email" "user@example.com"
|
|
121
185
|
|
|
122
|
-
#
|
|
123
|
-
chrome-cdp-cli
|
|
186
|
+
# Advanced interactions
|
|
187
|
+
chrome-cdp-cli drag "#draggable" "#dropzone"
|
|
188
|
+
chrome-cdp-cli press_key "Enter"
|
|
189
|
+
chrome-cdp-cli press_key "a" --modifiers Ctrl
|
|
190
|
+
chrome-cdp-cli upload_file "input[type='file']" "./document.pdf"
|
|
191
|
+
chrome-cdp-cli wait_for "#loading" --condition hidden
|
|
192
|
+
chrome-cdp-cli handle_dialog accept
|
|
124
193
|
|
|
125
|
-
#
|
|
126
|
-
chrome-cdp-cli
|
|
194
|
+
# Batch form filling
|
|
195
|
+
chrome-cdp-cli fill_form --fields '[{"selector":"#username","value":"john"},{"selector":"#password","value":"secret"}]'
|
|
127
196
|
|
|
128
|
-
# Monitor network
|
|
197
|
+
# Monitor console and network
|
|
198
|
+
chrome-cdp-cli get_console_message
|
|
129
199
|
chrome-cdp-cli get_network_request
|
|
130
200
|
|
|
131
201
|
# Install IDE integrations
|
|
132
|
-
chrome-cdp-cli
|
|
133
|
-
chrome-cdp-cli
|
|
202
|
+
chrome-cdp-cli install_cursor_command
|
|
203
|
+
chrome-cdp-cli install_claude_skill --skill-type personal
|
|
134
204
|
|
|
135
205
|
# Get help for all commands
|
|
136
206
|
chrome-cdp-cli --help
|
|
@@ -204,6 +274,110 @@ chrome-cdp-cli snapshot --filename dom-snapshot.json
|
|
|
204
274
|
chrome-cdp-cli screenshot --width 1920 --height 1080 --filename custom.png
|
|
205
275
|
```
|
|
206
276
|
|
|
277
|
+
#### Element Interaction
|
|
278
|
+
```bash
|
|
279
|
+
# Click on an element using CSS selector
|
|
280
|
+
chrome-cdp-cli click "#submit-button"
|
|
281
|
+
|
|
282
|
+
# Click with custom timeout
|
|
283
|
+
chrome-cdp-cli click ".slow-loading-button" --timeout 10000
|
|
284
|
+
|
|
285
|
+
# Click without waiting for element (fail immediately if not found)
|
|
286
|
+
chrome-cdp-cli click "#optional-element" --no-wait
|
|
287
|
+
|
|
288
|
+
# Hover over an element
|
|
289
|
+
chrome-cdp-cli hover "#menu-item"
|
|
290
|
+
|
|
291
|
+
# Hover over a dropdown trigger
|
|
292
|
+
chrome-cdp-cli hover ".dropdown-trigger"
|
|
293
|
+
|
|
294
|
+
# Fill a single form field
|
|
295
|
+
chrome-cdp-cli fill "#username" "john@example.com"
|
|
296
|
+
|
|
297
|
+
# Fill a password field
|
|
298
|
+
chrome-cdp-cli fill "input[type='password']" "secret123"
|
|
299
|
+
|
|
300
|
+
# Fill a textarea
|
|
301
|
+
chrome-cdp-cli fill "#message" "Hello, this is a test message"
|
|
302
|
+
|
|
303
|
+
# Select an option in a dropdown (by value or text)
|
|
304
|
+
chrome-cdp-cli fill "#country" "US"
|
|
305
|
+
chrome-cdp-cli fill "#country" "United States"
|
|
306
|
+
|
|
307
|
+
# Fill without clearing existing content
|
|
308
|
+
chrome-cdp-cli fill "#notes" " - Additional note" --no-clear
|
|
309
|
+
|
|
310
|
+
# Fill multiple form fields in batch
|
|
311
|
+
chrome-cdp-cli fill_form --fields '[
|
|
312
|
+
{"selector":"#username","value":"john@example.com"},
|
|
313
|
+
{"selector":"#password","value":"secret123"},
|
|
314
|
+
{"selector":"#country","value":"United States"}
|
|
315
|
+
]'
|
|
316
|
+
|
|
317
|
+
# Fill form from JSON file
|
|
318
|
+
echo '[
|
|
319
|
+
{"selector":"#firstName","value":"John"},
|
|
320
|
+
{"selector":"#lastName","value":"Doe"},
|
|
321
|
+
{"selector":"#email","value":"john.doe@example.com"}
|
|
322
|
+
]' > form-data.json
|
|
323
|
+
chrome-cdp-cli fill_form --fields-file form-data.json
|
|
324
|
+
|
|
325
|
+
# Fill form with custom options
|
|
326
|
+
chrome-cdp-cli fill_form --fields '[
|
|
327
|
+
{"selector":"#notes","value":"Additional information"}
|
|
328
|
+
]' --no-clear --timeout 10000 --stop-on-error
|
|
329
|
+
|
|
330
|
+
# Fill form and continue on errors (default behavior)
|
|
331
|
+
chrome-cdp-cli fill_form --fields '[
|
|
332
|
+
{"selector":"#field1","value":"value1"},
|
|
333
|
+
{"selector":"#nonexistent","value":"value2"},
|
|
334
|
+
{"selector":"#field3","value":"value3"}
|
|
335
|
+
]' --continue-on-error
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
#### Advanced Interactions
|
|
339
|
+
```bash
|
|
340
|
+
# Drag and drop operations
|
|
341
|
+
chrome-cdp-cli drag "#draggable-item" "#drop-zone"
|
|
342
|
+
|
|
343
|
+
# Drag with custom timeout
|
|
344
|
+
chrome-cdp-cli drag ".file-item" ".upload-area" --timeout 10000
|
|
345
|
+
|
|
346
|
+
# Keyboard input simulation
|
|
347
|
+
chrome-cdp-cli press_key "Enter"
|
|
348
|
+
chrome-cdp-cli press_key "Escape"
|
|
349
|
+
chrome-cdp-cli press_key "Tab"
|
|
350
|
+
|
|
351
|
+
# Keyboard input with modifiers
|
|
352
|
+
chrome-cdp-cli press_key "a" --modifiers Ctrl # Ctrl+A (Select All)
|
|
353
|
+
chrome-cdp-cli press_key "s" --modifiers Ctrl # Ctrl+S (Save)
|
|
354
|
+
chrome-cdp-cli press_key "c" --modifiers Ctrl,Shift # Ctrl+Shift+C
|
|
355
|
+
|
|
356
|
+
# Target specific elements for keyboard input
|
|
357
|
+
chrome-cdp-cli press_key "Enter" --selector "#search-input"
|
|
358
|
+
chrome-cdp-cli press_key "ArrowDown" --selector "#dropdown"
|
|
359
|
+
|
|
360
|
+
# File upload to file input elements
|
|
361
|
+
chrome-cdp-cli upload_file "input[type='file']" "./document.pdf"
|
|
362
|
+
chrome-cdp-cli upload_file "#file-input" "/path/to/image.jpg"
|
|
363
|
+
chrome-cdp-cli upload_file ".upload-field" "./test-data.csv"
|
|
364
|
+
|
|
365
|
+
# Wait for elements to appear or meet conditions
|
|
366
|
+
chrome-cdp-cli wait_for "#loading-spinner" # Wait for element to exist
|
|
367
|
+
chrome-cdp-cli wait_for "#modal" --condition visible # Wait for element to be visible
|
|
368
|
+
chrome-cdp-cli wait_for "#loading" --condition hidden # Wait for element to be hidden
|
|
369
|
+
chrome-cdp-cli wait_for "#submit-btn" --condition enabled # Wait for element to be enabled
|
|
370
|
+
chrome-cdp-cli wait_for "#processing-btn" --condition disabled # Wait for element to be disabled
|
|
371
|
+
chrome-cdp-cli wait_for "#slow-element" --timeout 30000 # Custom timeout
|
|
372
|
+
|
|
373
|
+
# Handle browser dialogs (alert, confirm, prompt)
|
|
374
|
+
chrome-cdp-cli handle_dialog accept # Accept dialog
|
|
375
|
+
chrome-cdp-cli handle_dialog dismiss # Dismiss dialog
|
|
376
|
+
chrome-cdp-cli handle_dialog accept --text "John Doe" # Handle prompt with text input
|
|
377
|
+
chrome-cdp-cli handle_dialog accept --text "" # Handle prompt with empty input
|
|
378
|
+
chrome-cdp-cli handle_dialog accept --timeout 10000 # Wait for dialog to appear
|
|
379
|
+
```
|
|
380
|
+
|
|
207
381
|
#### Console Monitoring
|
|
208
382
|
```bash
|
|
209
383
|
# Get latest console message
|
|
@@ -212,7 +386,7 @@ chrome-cdp-cli get_console_message
|
|
|
212
386
|
# List all console messages
|
|
213
387
|
chrome-cdp-cli list_console_messages
|
|
214
388
|
|
|
215
|
-
# Filter console messages
|
|
389
|
+
# Filter console messages by type
|
|
216
390
|
chrome-cdp-cli list_console_messages --filter '{"types":["error","warn"]}'
|
|
217
391
|
```
|
|
218
392
|
|
|
@@ -224,34 +398,34 @@ chrome-cdp-cli get_network_request
|
|
|
224
398
|
# List all network requests
|
|
225
399
|
chrome-cdp-cli list_network_requests
|
|
226
400
|
|
|
227
|
-
# Filter network requests
|
|
401
|
+
# Filter network requests by method
|
|
228
402
|
chrome-cdp-cli list_network_requests --filter '{"methods":["POST"],"statusCodes":[200,201]}'
|
|
229
403
|
```
|
|
230
404
|
|
|
231
405
|
#### IDE Integration
|
|
232
406
|
```bash
|
|
233
407
|
# Install Cursor command (creates .cursor/commands/cdp-cli.md)
|
|
234
|
-
chrome-cdp-cli
|
|
408
|
+
chrome-cdp-cli install_cursor_command
|
|
235
409
|
|
|
236
410
|
# Install Cursor command with --force (bypasses directory validation)
|
|
237
|
-
chrome-cdp-cli
|
|
411
|
+
chrome-cdp-cli install_cursor_command --force
|
|
238
412
|
|
|
239
413
|
# Install Claude skill for project (creates .claude/skills/cdp-cli/SKILL.md)
|
|
240
|
-
chrome-cdp-cli
|
|
414
|
+
chrome-cdp-cli install_claude_skill
|
|
241
415
|
|
|
242
416
|
# Install Claude skill for personal use (creates ~/.claude/skills/cdp-cli/SKILL.md)
|
|
243
|
-
chrome-cdp-cli
|
|
417
|
+
chrome-cdp-cli install_claude_skill --skill-type personal
|
|
244
418
|
|
|
245
419
|
# Install Claude skill with examples and references
|
|
246
|
-
chrome-cdp-cli
|
|
420
|
+
chrome-cdp-cli install_claude_skill --include-examples --include-references
|
|
247
421
|
|
|
248
422
|
# Install with custom directory
|
|
249
|
-
chrome-cdp-cli
|
|
250
|
-
chrome-cdp-cli
|
|
423
|
+
chrome-cdp-cli install_cursor_command --target-directory /custom/path/.cursor/commands
|
|
424
|
+
chrome-cdp-cli install_claude_skill --target-directory /custom/path/.claude/skills
|
|
251
425
|
|
|
252
426
|
# Force install (bypasses directory validation)
|
|
253
|
-
chrome-cdp-cli
|
|
254
|
-
chrome-cdp-cli
|
|
427
|
+
chrome-cdp-cli install_cursor_command --force
|
|
428
|
+
chrome-cdp-cli install_claude_skill --force
|
|
255
429
|
```
|
|
256
430
|
|
|
257
431
|
### đ§ Available via Eval Workarounds
|
|
@@ -276,14 +450,15 @@ chrome-cdp-cli eval "window.history.forward()"
|
|
|
276
450
|
|
|
277
451
|
#### Element Interaction
|
|
278
452
|
```bash
|
|
279
|
-
#
|
|
280
|
-
chrome-cdp-cli
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
chrome-cdp-cli eval "document.querySelector('#email').value = 'user@example.com'"
|
|
453
|
+
# Native commands (recommended)
|
|
454
|
+
chrome-cdp-cli click "#button"
|
|
455
|
+
chrome-cdp-cli hover ".menu-item"
|
|
456
|
+
chrome-cdp-cli fill "#email" "user@example.com"
|
|
284
457
|
|
|
285
|
-
#
|
|
458
|
+
# Via eval (still available for complex scenarios)
|
|
459
|
+
chrome-cdp-cli eval "document.querySelector('#button').click()"
|
|
286
460
|
chrome-cdp-cli eval "document.querySelector('.menu-item').dispatchEvent(new MouseEvent('mouseover'))"
|
|
461
|
+
chrome-cdp-cli eval "document.querySelector('#email').value = 'user@example.com'"
|
|
287
462
|
|
|
288
463
|
# Check if element exists
|
|
289
464
|
chrome-cdp-cli eval "!!document.querySelector('#element')"
|
|
@@ -297,7 +472,18 @@ chrome-cdp-cli eval "document.querySelector('#element').getAttribute('class')"
|
|
|
297
472
|
|
|
298
473
|
#### Form Handling
|
|
299
474
|
```bash
|
|
300
|
-
#
|
|
475
|
+
# Native batch form filling (recommended)
|
|
476
|
+
chrome-cdp-cli fill_form --fields '[
|
|
477
|
+
{"selector":"#name","value":"John Doe"},
|
|
478
|
+
{"selector":"#email","value":"john@example.com"},
|
|
479
|
+
{"selector":"#phone","value":"123-456-7890"}
|
|
480
|
+
]'
|
|
481
|
+
|
|
482
|
+
# Native single field filling
|
|
483
|
+
chrome-cdp-cli fill "#name" "John Doe"
|
|
484
|
+
chrome-cdp-cli fill "#email" "john@example.com"
|
|
485
|
+
|
|
486
|
+
# Via eval (for complex form operations)
|
|
301
487
|
chrome-cdp-cli eval "
|
|
302
488
|
document.querySelector('#name').value = 'John Doe';
|
|
303
489
|
document.querySelector('#email').value = 'john@example.com';
|
|
@@ -307,7 +493,10 @@ document.querySelector('#phone').value = '123-456-7890';
|
|
|
307
493
|
# Submit form
|
|
308
494
|
chrome-cdp-cli eval "document.querySelector('#myform').submit()"
|
|
309
495
|
|
|
310
|
-
# Select dropdown option
|
|
496
|
+
# Select dropdown option (native)
|
|
497
|
+
chrome-cdp-cli fill "#dropdown" "option1"
|
|
498
|
+
|
|
499
|
+
# Select dropdown option (via eval)
|
|
311
500
|
chrome-cdp-cli eval "document.querySelector('#dropdown').value = 'option1'"
|
|
312
501
|
|
|
313
502
|
# Check checkbox
|
|
@@ -470,7 +659,6 @@ new Promise(resolve => {
|
|
|
470
659
|
### Current Limitations
|
|
471
660
|
|
|
472
661
|
- **No native page management**: Creating, closing, and switching between tabs requires manual implementation
|
|
473
|
-
- **No native element interaction**: Clicking, hovering, and form filling must be done via eval
|
|
474
662
|
- **No performance profiling**: Advanced performance analysis requires manual JavaScript
|
|
475
663
|
- **No device emulation**: Mobile/tablet simulation not yet implemented
|
|
476
664
|
- **Basic output formatting**: Advanced JSON/text formatting options not available
|
|
@@ -481,9 +669,10 @@ new Promise(resolve => {
|
|
|
481
669
|
- `new_page`, `close_page`, `list_pages`, `select_page`
|
|
482
670
|
- Direct CDP Target domain integration
|
|
483
671
|
|
|
484
|
-
2. **Native Element Interaction**
|
|
485
|
-
- `click`, `hover`, `fill`, `
|
|
672
|
+
2. **Native Element Interaction** â
**COMPLETED**
|
|
673
|
+
- `click`, `hover`, `fill`, `fill_form` commands
|
|
486
674
|
- CSS selector-based element targeting
|
|
675
|
+
- Comprehensive form filling with batch operations
|
|
487
676
|
|
|
488
677
|
3. **Performance Analysis**
|
|
489
678
|
- `performance_start_trace`, `performance_stop_trace`
|
|
@@ -498,15 +687,210 @@ new Promise(resolve => {
|
|
|
498
687
|
- Quiet and verbose modes
|
|
499
688
|
- Custom output templates
|
|
500
689
|
|
|
501
|
-
### Why
|
|
690
|
+
### Why Eval-First Design? (Built for LLMs)
|
|
691
|
+
|
|
692
|
+
**This is not a workaround - it's the core design philosophy optimized for LLM workflows:**
|
|
693
|
+
|
|
694
|
+
1. **đ§ LLMs are JavaScript Experts**: Large Language Models excel at writing JavaScript. They can generate complex automation scripts, handle async operations, and adapt to different scenarios - all naturally in JavaScript.
|
|
695
|
+
|
|
696
|
+
2. **⥠Rapid Script Validation**: The perfect workflow for LLMs: Write JavaScript â Execute via `eval` â See Results â Refine. This iterative loop is where LLMs shine.
|
|
697
|
+
|
|
698
|
+
3. **đ Maximum Flexibility**: Any browser task, any complexity, any scenario - all through JavaScript. No waiting for specific command implementations.
|
|
699
|
+
|
|
700
|
+
4. **đ€ AI-Native Workflow**: When you ask Claude or Cursor to automate something, they write JavaScript - exactly what `eval` executes. Perfect alignment.
|
|
701
|
+
|
|
702
|
+
5. **đ Natural Language â Automation**: "Click the submit button" â AI generates `document.querySelector('#submit').click()` â Executes instantly.
|
|
703
|
+
|
|
704
|
+
6. **đŻ Context-Aware**: AI understands your project and can write automation scripts that fit your specific needs.
|
|
705
|
+
|
|
706
|
+
7. **⥠Instant Iteration**: LLMs can adjust scripts based on results immediately - no need to wait for feature releases.
|
|
707
|
+
|
|
708
|
+
**This tool is built for LLM-assisted development. The eval-first approach, combined with IDE integrations (Cursor commands & Claude skills), creates a seamless workflow where AI assistants can automate browser tasks as part of your development process.**
|
|
709
|
+
|
|
710
|
+
## Form Filling & Element Interaction
|
|
711
|
+
|
|
712
|
+
The CLI now includes native commands for element interaction and form filling, designed to work seamlessly with both simple and complex automation scenarios.
|
|
713
|
+
|
|
714
|
+
### Single Field Filling
|
|
715
|
+
|
|
716
|
+
```bash
|
|
717
|
+
# Fill a text input
|
|
718
|
+
chrome-cdp-cli fill "#username" "john@example.com"
|
|
719
|
+
|
|
720
|
+
# Fill a password field
|
|
721
|
+
chrome-cdp-cli fill "input[type='password']" "secret123"
|
|
722
|
+
|
|
723
|
+
# Fill a textarea
|
|
724
|
+
chrome-cdp-cli fill "#message" "Hello, this is a test message"
|
|
725
|
+
|
|
726
|
+
# Select dropdown option (by value or text)
|
|
727
|
+
chrome-cdp-cli fill "#country" "US"
|
|
728
|
+
chrome-cdp-cli fill "#country" "United States"
|
|
729
|
+
|
|
730
|
+
# Fill without clearing existing content
|
|
731
|
+
chrome-cdp-cli fill "#notes" " - Additional note" --no-clear
|
|
732
|
+
|
|
733
|
+
# Fill with custom timeout
|
|
734
|
+
chrome-cdp-cli fill ".slow-loading-field" "value" --timeout 10000
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
### Batch Form Filling
|
|
738
|
+
|
|
739
|
+
```bash
|
|
740
|
+
# Fill multiple fields at once
|
|
741
|
+
chrome-cdp-cli fill_form --fields '[
|
|
742
|
+
{"selector":"#firstName","value":"John"},
|
|
743
|
+
{"selector":"#lastName","value":"Doe"},
|
|
744
|
+
{"selector":"#email","value":"john.doe@example.com"},
|
|
745
|
+
{"selector":"#country","value":"United States"}
|
|
746
|
+
]'
|
|
747
|
+
|
|
748
|
+
# Fill form from JSON file
|
|
749
|
+
echo '[
|
|
750
|
+
{"selector":"#username","value":"testuser"},
|
|
751
|
+
{"selector":"#password","value":"testpass"},
|
|
752
|
+
{"selector":"#confirmPassword","value":"testpass"}
|
|
753
|
+
]' > login-form.json
|
|
754
|
+
chrome-cdp-cli fill_form --fields-file login-form.json
|
|
755
|
+
|
|
756
|
+
# Advanced options
|
|
757
|
+
chrome-cdp-cli fill_form --fields '[
|
|
758
|
+
{"selector":"#field1","value":"value1"},
|
|
759
|
+
{"selector":"#field2","value":"value2"}
|
|
760
|
+
]' --no-clear --timeout 15000 --stop-on-error
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
### Element Interaction
|
|
764
|
+
|
|
765
|
+
```bash
|
|
766
|
+
# Click elements
|
|
767
|
+
chrome-cdp-cli click "#submit-button"
|
|
768
|
+
chrome-cdp-cli click ".menu-item" --timeout 5000
|
|
769
|
+
|
|
770
|
+
# Hover over elements
|
|
771
|
+
chrome-cdp-cli hover "#dropdown-trigger"
|
|
772
|
+
chrome-cdp-cli hover ".tooltip-element" --no-wait
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
### Form Filling Options
|
|
776
|
+
|
|
777
|
+
**Single Field Options (`fill` command):**
|
|
778
|
+
- `--wait-for-element` / `--no-wait`: Wait for element to appear (default: true)
|
|
779
|
+
- `--timeout <ms>`: Timeout for waiting (default: 5000ms)
|
|
780
|
+
- `--clear-first` / `--no-clear`: Clear field before filling (default: true)
|
|
781
|
+
|
|
782
|
+
**Batch Form Options (`fill_form` command):**
|
|
783
|
+
- `--fields <json>`: JSON array of field objects
|
|
784
|
+
- `--fields-file <file>`: JSON file containing field array
|
|
785
|
+
- `--wait-for-elements` / `--no-wait`: Wait for all elements (default: true)
|
|
786
|
+
- `--timeout <ms>`: Timeout for each field (default: 5000ms)
|
|
787
|
+
- `--clear-first` / `--no-clear`: Clear all fields before filling (default: true)
|
|
788
|
+
- `--continue-on-error` / `--stop-on-error`: Continue if field fails (default: continue)
|
|
789
|
+
|
|
790
|
+
### Supported Form Elements
|
|
791
|
+
|
|
792
|
+
**Input Types:**
|
|
793
|
+
- Text inputs (`<input type="text">`)
|
|
794
|
+
- Email inputs (`<input type="email">`)
|
|
795
|
+
- Password inputs (`<input type="password">`)
|
|
796
|
+
- Number inputs (`<input type="number">`)
|
|
797
|
+
- Search inputs (`<input type="search">`)
|
|
798
|
+
- URL inputs (`<input type="url">`)
|
|
799
|
+
|
|
800
|
+
**Other Elements:**
|
|
801
|
+
- Textareas (`<textarea>`)
|
|
802
|
+
- Select dropdowns (`<select>`) - matches by value or text content
|
|
803
|
+
|
|
804
|
+
### Error Handling
|
|
805
|
+
|
|
806
|
+
The form filling commands include comprehensive error handling:
|
|
807
|
+
|
|
808
|
+
```bash
|
|
809
|
+
# Continue filling other fields if one fails (default)
|
|
810
|
+
chrome-cdp-cli fill_form --fields '[
|
|
811
|
+
{"selector":"#valid-field","value":"works"},
|
|
812
|
+
{"selector":"#invalid-field","value":"fails"},
|
|
813
|
+
{"selector":"#another-field","value":"also works"}
|
|
814
|
+
]' --continue-on-error
|
|
815
|
+
|
|
816
|
+
# Stop on first error
|
|
817
|
+
chrome-cdp-cli fill_form --fields '[
|
|
818
|
+
{"selector":"#field1","value":"value1"},
|
|
819
|
+
{"selector":"#nonexistent","value":"value2"}
|
|
820
|
+
]' --stop-on-error
|
|
821
|
+
```
|
|
822
|
+
|
|
823
|
+
### Integration with Eval
|
|
502
824
|
|
|
503
|
-
|
|
825
|
+
For complex scenarios, combine native commands with eval:
|
|
826
|
+
|
|
827
|
+
```bash
|
|
828
|
+
# Use native commands for standard operations
|
|
829
|
+
chrome-cdp-cli fill "#username" "john@example.com"
|
|
830
|
+
chrome-cdp-cli fill "#password" "secret123"
|
|
831
|
+
|
|
832
|
+
# Use eval for complex validation or custom logic
|
|
833
|
+
chrome-cdp-cli eval "
|
|
834
|
+
// Validate form before submission
|
|
835
|
+
const username = document.querySelector('#username').value;
|
|
836
|
+
const password = document.querySelector('#password').value;
|
|
837
|
+
if (username && password && password.length >= 8) {
|
|
838
|
+
document.querySelector('#submit').click();
|
|
839
|
+
return 'Form submitted successfully';
|
|
840
|
+
} else {
|
|
841
|
+
return 'Validation failed';
|
|
842
|
+
}
|
|
843
|
+
"
|
|
844
|
+
```
|
|
845
|
+
|
|
846
|
+
## Quick Reference
|
|
847
|
+
|
|
848
|
+
### Form Filling Commands
|
|
849
|
+
|
|
850
|
+
```bash
|
|
851
|
+
# Single field filling
|
|
852
|
+
chrome-cdp-cli fill "#username" "john@example.com"
|
|
853
|
+
chrome-cdp-cli fill "#country" "United States" # Works with dropdowns
|
|
854
|
+
|
|
855
|
+
# Batch form filling
|
|
856
|
+
chrome-cdp-cli fill_form --fields '[
|
|
857
|
+
{"selector":"#username","value":"john"},
|
|
858
|
+
{"selector":"#password","value":"secret"}
|
|
859
|
+
]'
|
|
860
|
+
|
|
861
|
+
# From JSON file
|
|
862
|
+
chrome-cdp-cli fill_form --fields-file form-data.json
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
### Element Interaction Commands
|
|
866
|
+
|
|
867
|
+
```bash
|
|
868
|
+
# Click and hover
|
|
869
|
+
chrome-cdp-cli click "#submit-button"
|
|
870
|
+
chrome-cdp-cli hover ".dropdown-trigger"
|
|
871
|
+
|
|
872
|
+
# With options
|
|
873
|
+
chrome-cdp-cli fill "#field" "value" --timeout 10000 --no-clear
|
|
874
|
+
chrome-cdp-cli click "#button" --no-wait
|
|
875
|
+
```
|
|
876
|
+
|
|
877
|
+
### Core Commands
|
|
878
|
+
|
|
879
|
+
```bash
|
|
880
|
+
# JavaScript execution
|
|
881
|
+
chrome-cdp-cli eval "document.title"
|
|
882
|
+
chrome-cdp-cli eval --file script.js
|
|
883
|
+
|
|
884
|
+
# Visual capture
|
|
885
|
+
chrome-cdp-cli screenshot --filename page.png
|
|
886
|
+
chrome-cdp-cli snapshot --filename dom.json
|
|
887
|
+
|
|
888
|
+
# Monitoring
|
|
889
|
+
chrome-cdp-cli get_console_message
|
|
890
|
+
chrome-cdp-cli list_network_requests
|
|
891
|
+
```
|
|
504
892
|
|
|
505
|
-
|
|
506
|
-
- **Maximum flexibility**: Any JavaScript operation is possible
|
|
507
|
-
- **Learning opportunity**: Better understanding of browser APIs
|
|
508
|
-
- **Custom solutions**: Tailor automation to specific needs
|
|
509
|
-
- **Future-proof**: Works with any web technology
|
|
893
|
+
For detailed documentation, see the [Form Filling Guide](docs/FORM_FILLING.md).
|
|
510
894
|
|
|
511
895
|
## Configuration
|
|
512
896
|
|
|
@@ -733,6 +1117,7 @@ MIT License - see [LICENSE](LICENSE) file for details.
|
|
|
733
1117
|
## Support
|
|
734
1118
|
|
|
735
1119
|
- đ [Documentation](https://github.com/nickxiao42/chrome-devtools-cli/wiki)
|
|
1120
|
+
- đ [Form Filling Guide](docs/FORM_FILLING.md)
|
|
736
1121
|
- đ [Issue Tracker](https://github.com/nickxiao42/chrome-devtools-cli/issues)
|
|
737
1122
|
- đŹ [Discussions](https://github.com/nickxiao42/chrome-devtools-cli/discussions)
|
|
738
1123
|
|
|
@@ -23,6 +23,15 @@ class CLIApplication {
|
|
|
23
23
|
this.cli.registerHandler(new handlers_1.ListNetworkRequestsHandler());
|
|
24
24
|
this.cli.registerHandler(new handlers_1.InstallCursorCommandHandler());
|
|
25
25
|
this.cli.registerHandler(new handlers_1.InstallClaudeSkillHandler());
|
|
26
|
+
this.cli.registerHandler(new handlers_1.ClickHandler());
|
|
27
|
+
this.cli.registerHandler(new handlers_1.HoverHandler());
|
|
28
|
+
this.cli.registerHandler(new handlers_1.FillHandler());
|
|
29
|
+
this.cli.registerHandler(new handlers_1.FillFormHandler());
|
|
30
|
+
this.cli.registerHandler(new handlers_1.DragHandler());
|
|
31
|
+
this.cli.registerHandler(new handlers_1.PressKeyHandler());
|
|
32
|
+
this.cli.registerHandler(new handlers_1.UploadFileHandler());
|
|
33
|
+
this.cli.registerHandler(new handlers_1.WaitForHandler());
|
|
34
|
+
this.cli.registerHandler(new handlers_1.HandleDialogHandler());
|
|
26
35
|
}
|
|
27
36
|
async run(argv) {
|
|
28
37
|
try {
|
|
@@ -87,7 +87,7 @@ class CommandRouter {
|
|
|
87
87
|
case 'disconnect':
|
|
88
88
|
return this.executeDisconnectCommand();
|
|
89
89
|
case 'install_cursor_command':
|
|
90
|
-
case 'install_claude_skill':
|
|
90
|
+
case 'install_claude_skill': {
|
|
91
91
|
const handler = this.registry.get(command.name);
|
|
92
92
|
if (!handler) {
|
|
93
93
|
return {
|
|
@@ -97,6 +97,7 @@ class CommandRouter {
|
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
return await handler.execute(null, command.args);
|
|
100
|
+
}
|
|
100
101
|
default:
|
|
101
102
|
return {
|
|
102
103
|
success: false,
|
|
@@ -241,11 +242,21 @@ For more information about a specific command, use:
|
|
|
241
242
|
'eval': 'Execute JavaScript code',
|
|
242
243
|
'click': 'Click element',
|
|
243
244
|
'fill': 'Fill form field',
|
|
245
|
+
'fill_form': 'Fill multiple form fields in batch',
|
|
244
246
|
'hover': 'Hover over element',
|
|
247
|
+
'drag': 'Perform drag and drop operations',
|
|
248
|
+
'press_key': 'Simulate keyboard input with modifiers',
|
|
249
|
+
'upload_file': 'Upload files to file input elements',
|
|
250
|
+
'wait_for': 'Wait for elements to appear or meet conditions',
|
|
251
|
+
'handle_dialog': 'Handle browser dialogs (alert, confirm, prompt)',
|
|
245
252
|
'screenshot': 'Capture page screenshot',
|
|
246
253
|
'snapshot': 'Capture DOM snapshot with structure and styles',
|
|
247
254
|
'console-messages': 'Get console messages',
|
|
248
255
|
'network-requests': 'Get network requests',
|
|
256
|
+
'get_console_message': 'Get the latest console message',
|
|
257
|
+
'list_console_messages': 'List all console messages with filtering',
|
|
258
|
+
'get_network_request': 'Get the latest network request',
|
|
259
|
+
'list_network_requests': 'List all network requests with filtering',
|
|
249
260
|
'install_cursor_command': 'Install Cursor IDE commands for Chrome automation',
|
|
250
261
|
'install_claude_skill': 'Install Claude Code skill for Chrome automation',
|
|
251
262
|
'help': 'Show help information'
|