chrome-cdp-cli 1.0.2 → 1.2.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
@@ -2,17 +2,47 @@
2
2
 
3
3
  A powerful command-line tool for controlling Chrome browser instances via the Chrome DevTools Protocol (CDP). This tool provides programmatic access to browser automation, debugging, and inspection capabilities without requiring a graphical interface.
4
4
 
5
+ ## Implementation Status
6
+
7
+ ### ✅ Fully Implemented Features
8
+
9
+ - 🔗 **Connection Management**: Connect to local or remote Chrome instances with auto-discovery
10
+ - ⚡ **JavaScript Execution**: Execute JavaScript code in browser context with full async support and file execution
11
+ - 📸 **Visual Capture**: Take screenshots and capture complete DOM snapshots with layout information
12
+ - 📊 **Console Monitoring**: Real-time console message capture with filtering and storage
13
+ - 🌐 **Network Monitoring**: Real-time network request/response monitoring with comprehensive filtering
14
+ - 🔧 **CLI Interface**: Full command-line interface with argument parsing and routing
15
+ - 🛠️ **IDE Integration**: Install Cursor commands and Claude skills with directory validation and --force option
16
+ - 📦 **Build System**: Complete TypeScript build pipeline with testing framework
17
+
18
+ ### 🚧 Eval Workaround Available
19
+
20
+ These features are not directly implemented but can be achieved using the `eval` command:
21
+
22
+ - 📄 **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
+ - 🚀 **Performance Data**: `eval "performance.now()"` or `eval "performance.getEntriesByType('navigation')"`
27
+ - 📱 **User Agent**: `eval "navigator.userAgent"`
28
+ - 🌐 **Network Requests**: `eval "fetch('/api').then(r => r.json())"`
29
+
30
+ ### ⏳ Not Yet Implemented
31
+
32
+ - 📄 **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
+ - 🚀 **Performance Analysis**: Native performance profiling and metrics collection
35
+ - 📱 **Device Emulation**: Native device and network condition simulation
36
+ - 📊 **Output Formatting**: Advanced JSON/text formatting with quiet/verbose modes
37
+
5
38
  ## Features
6
39
 
7
40
  - 🔗 **Connection Management**: Connect to local or remote Chrome instances
8
- - 📄 **Page Management**: Navigate, create, close, and manage browser tabs
9
41
  - ⚡ **JavaScript Execution**: Execute JavaScript code in browser context with full async support
10
42
  - 📸 **Visual Capture**: Take screenshots and capture HTML content
11
- - 🖱️ **Element Interaction**: Click, hover, fill forms, and interact with page elements
12
43
  - 📊 **Monitoring**: Monitor console messages and network requests in real-time
13
- - 🚀 **Performance Analysis**: Profile page performance and analyze metrics
14
- - 📱 **Device Emulation**: Simulate different devices and network conditions
15
44
  - 🔧 **Flexible Output**: Support for JSON and human-readable text output formats
45
+ - 🚧 **Eval Workarounds**: Many advanced features available through JavaScript execution
16
46
 
17
47
  ## Installation
18
48
 
@@ -77,17 +107,30 @@ chrome-cdp-cli eval "document.title"
77
107
  # Or use with npx (no installation needed)
78
108
  npx chrome-cdp-cli eval "document.title"
79
109
 
80
- # Navigate to a website
81
- chrome-cdp-cli navigate_page "https://example.com"
110
+ # Navigate to a website (via eval)
111
+ chrome-cdp-cli eval "window.location.href = 'https://example.com'"
82
112
 
83
113
  # Take a screenshot
84
114
  chrome-cdp-cli screenshot --filename screenshot.png
85
115
 
86
- # Click an element
87
- chrome-cdp-cli click "#submit-button"
116
+ # Capture DOM snapshot
117
+ chrome-cdp-cli snapshot --filename dom-snapshot.json
118
+
119
+ # Click an element (via eval)
120
+ chrome-cdp-cli eval "document.querySelector('#submit-button').click()"
121
+
122
+ # Fill a form field (via eval)
123
+ chrome-cdp-cli eval "document.querySelector('#email').value = 'user@example.com'"
124
+
125
+ # Monitor console messages
126
+ chrome-cdp-cli get_console_message
88
127
 
89
- # Fill a form field
90
- chrome-cdp-cli fill "#email" "user@example.com"
128
+ # Monitor network requests
129
+ chrome-cdp-cli get_network_request
130
+
131
+ # Install IDE integrations
132
+ chrome-cdp-cli install-cursor-command
133
+ chrome-cdp-cli install-claude-skill --skill-type personal
91
134
 
92
135
  # Get help for all commands
93
136
  chrome-cdp-cli --help
@@ -112,7 +155,23 @@ All commands support these connection options:
112
155
  - `--quiet`: Suppress non-essential output
113
156
  - `--verbose`: Enable detailed logging
114
157
 
115
- ### Core Commands
158
+ ## Command Reference
159
+
160
+ ### Connection Options
161
+
162
+ All commands support these connection options:
163
+
164
+ - `--host <host>`: Chrome host (default: localhost)
165
+ - `--port <port>`: DevTools port (default: 9222)
166
+ - `--timeout <ms>`: Command timeout in milliseconds (default: 30000)
167
+
168
+ ### Output Options
169
+
170
+ - `--format <format>`: Output format - 'json' or 'text' (default: text)
171
+ - `--quiet`: Suppress non-essential output
172
+ - `--verbose`: Enable detailed logging
173
+
174
+ ### ✅ Implemented Commands
116
175
 
117
176
  #### JavaScript Execution
118
177
  ```bash
@@ -130,57 +189,325 @@ npx chrome-cdp-cli eval "document.title"
130
189
  npx chrome-cdp-cli eval --file script.js
131
190
  ```
132
191
 
192
+ #### Visual Capture
193
+ ```bash
194
+ # Take screenshot
195
+ chrome-cdp-cli screenshot --filename screenshot.png
196
+
197
+ # Full page screenshot
198
+ chrome-cdp-cli screenshot --full-page --filename fullpage.png
199
+
200
+ # DOM snapshot with complete layout information
201
+ chrome-cdp-cli snapshot --filename dom-snapshot.json
202
+
203
+ # Custom dimensions
204
+ chrome-cdp-cli screenshot --width 1920 --height 1080 --filename custom.png
205
+ ```
206
+
207
+ #### Console Monitoring
208
+ ```bash
209
+ # Get latest console message
210
+ chrome-cdp-cli get_console_message
211
+
212
+ # List all console messages
213
+ chrome-cdp-cli list_console_messages
214
+
215
+ # Filter console messages
216
+ chrome-cdp-cli list_console_messages --filter '{"types":["error","warn"]}'
217
+ ```
218
+
219
+ #### Network Monitoring
220
+ ```bash
221
+ # Get latest network request
222
+ chrome-cdp-cli get_network_request
223
+
224
+ # List all network requests
225
+ chrome-cdp-cli list_network_requests
226
+
227
+ # Filter network requests
228
+ chrome-cdp-cli list_network_requests --filter '{"methods":["POST"],"statusCodes":[200,201]}'
229
+ ```
230
+
231
+ #### IDE Integration
232
+ ```bash
233
+ # Install Cursor command (creates .cursor/commands/cdp-cli.md)
234
+ chrome-cdp-cli install-cursor-command
235
+
236
+ # Install Cursor command with --force (bypasses directory validation)
237
+ chrome-cdp-cli install-cursor-command --force
238
+
239
+ # Install Claude skill for project (creates .claude/skills/cdp-cli/SKILL.md)
240
+ chrome-cdp-cli install-claude-skill
241
+
242
+ # Install Claude skill for personal use (creates ~/.claude/skills/cdp-cli/SKILL.md)
243
+ chrome-cdp-cli install-claude-skill --skill-type personal
244
+
245
+ # Install Claude skill with examples and references
246
+ chrome-cdp-cli install-claude-skill --include-examples --include-references
247
+
248
+ # Install with custom directory
249
+ chrome-cdp-cli install-cursor-command --target-directory /custom/path/.cursor/commands
250
+ chrome-cdp-cli install-claude-skill --target-directory /custom/path/.claude/skills
251
+
252
+ # Force install (bypasses directory validation)
253
+ chrome-cdp-cli install-cursor-command --force
254
+ chrome-cdp-cli install-claude-skill --force
255
+ ```
256
+
257
+ ### 🚧 Available via Eval Workarounds
258
+
133
259
  #### Page Management
134
260
  ```bash
135
261
  # Navigate to URL
136
- chrome-cdp-cli navigate_page "https://example.com"
262
+ chrome-cdp-cli eval "window.location.href = 'https://example.com'"
137
263
 
138
- # Create new tab
139
- chrome-cdp-cli new_page
264
+ # Get current URL
265
+ chrome-cdp-cli eval "window.location.href"
140
266
 
141
- # List all pages
142
- chrome-cdp-cli list_pages
267
+ # Reload page
268
+ chrome-cdp-cli eval "window.location.reload()"
143
269
 
144
- # Close current page
145
- chrome-cdp-cli close_page
270
+ # Go back
271
+ chrome-cdp-cli eval "window.history.back()"
146
272
 
147
- # Switch to specific page
148
- chrome-cdp-cli select_page --id "page-id"
273
+ # Go forward
274
+ chrome-cdp-cli eval "window.history.forward()"
149
275
  ```
150
276
 
151
277
  #### Element Interaction
152
278
  ```bash
153
279
  # Click element
154
- chrome-cdp-cli click "#button"
280
+ chrome-cdp-cli eval "document.querySelector('#button').click()"
155
281
 
156
282
  # Fill input field
157
- chrome-cdp-cli fill "#email" "user@example.com"
283
+ chrome-cdp-cli eval "document.querySelector('#email').value = 'user@example.com'"
284
+
285
+ # Hover over element (trigger mouseover event)
286
+ chrome-cdp-cli eval "document.querySelector('.menu-item').dispatchEvent(new MouseEvent('mouseover'))"
287
+
288
+ # Check if element exists
289
+ chrome-cdp-cli eval "!!document.querySelector('#element')"
158
290
 
159
- # Hover over element
160
- chrome-cdp-cli hover ".menu-item"
291
+ # Get element text
292
+ chrome-cdp-cli eval "document.querySelector('#element').textContent"
161
293
 
162
- # Wait for element
163
- chrome-cdp-cli wait_for "#loading" --timeout 5000
294
+ # Get element attributes
295
+ chrome-cdp-cli eval "document.querySelector('#element').getAttribute('class')"
164
296
  ```
165
297
 
166
- #### Visual Capture
298
+ #### Form Handling
167
299
  ```bash
168
- # Take screenshot
169
- chrome-cdp-cli screenshot --filename screenshot.png
300
+ # Fill multiple form fields
301
+ chrome-cdp-cli eval "
302
+ document.querySelector('#name').value = 'John Doe';
303
+ document.querySelector('#email').value = 'john@example.com';
304
+ document.querySelector('#phone').value = '123-456-7890';
305
+ "
170
306
 
171
- # Full page screenshot
172
- chrome-cdp-cli screenshot --full-page --filename fullpage.png
307
+ # Submit form
308
+ chrome-cdp-cli eval "document.querySelector('#myform').submit()"
173
309
 
174
- # DOM snapshot
175
- chrome-cdp-cli snapshot --filename dom-snapshot.json
310
+ # Select dropdown option
311
+ chrome-cdp-cli eval "document.querySelector('#dropdown').value = 'option1'"
176
312
 
177
- # Custom dimensions
178
- chrome-cdp-cli screenshot --width 1920 --height 1080 --filename custom.png
313
+ # Check checkbox
314
+ chrome-cdp-cli eval "document.querySelector('#checkbox').checked = true"
315
+ ```
316
+
317
+ #### Content Extraction
318
+ ```bash
319
+ # Get page HTML
320
+ chrome-cdp-cli eval "document.documentElement.outerHTML"
321
+
322
+ # Get page title
323
+ chrome-cdp-cli eval "document.title"
324
+
325
+ # Get all links
326
+ chrome-cdp-cli eval "Array.from(document.querySelectorAll('a')).map(a => a.href)"
179
327
 
180
- # Get HTML content
181
- chrome-cdp-cli get_html --output page.html
328
+ # Get all images
329
+ chrome-cdp-cli eval "Array.from(document.querySelectorAll('img')).map(img => img.src)"
330
+
331
+ # Extract table data
332
+ chrome-cdp-cli eval "Array.from(document.querySelectorAll('table tr')).map(row => Array.from(row.cells).map(cell => cell.textContent))"
333
+ ```
334
+
335
+ #### Performance Monitoring
336
+ ```bash
337
+ # Get performance timing
338
+ chrome-cdp-cli eval "performance.timing"
339
+
340
+ # Get navigation entries
341
+ chrome-cdp-cli eval "performance.getEntriesByType('navigation')"
342
+
343
+ # Get resource entries
344
+ chrome-cdp-cli eval "performance.getEntriesByType('resource')"
345
+
346
+ # Get current timestamp
347
+ chrome-cdp-cli eval "performance.now()"
348
+
349
+ # Measure performance
350
+ chrome-cdp-cli eval "
351
+ performance.mark('start');
352
+ // ... some operation ...
353
+ performance.mark('end');
354
+ performance.measure('operation', 'start', 'end');
355
+ performance.getEntriesByName('operation')[0].duration;
356
+ "
357
+ ```
358
+
359
+ #### Network Operations
360
+ ```bash
361
+ # Make HTTP request
362
+ chrome-cdp-cli eval "fetch('/api/data').then(r => r.json())"
363
+
364
+ # POST data
365
+ chrome-cdp-cli eval "
366
+ fetch('/api/users', {
367
+ method: 'POST',
368
+ headers: {'Content-Type': 'application/json'},
369
+ body: JSON.stringify({name: 'John', email: 'john@example.com'})
370
+ }).then(r => r.json())
371
+ "
372
+
373
+ # Check network connectivity
374
+ chrome-cdp-cli eval "navigator.onLine"
182
375
  ```
183
376
 
377
+ #### Browser Information
378
+ ```bash
379
+ # Get user agent
380
+ chrome-cdp-cli eval "navigator.userAgent"
381
+
382
+ # Get viewport size
383
+ chrome-cdp-cli eval "{width: window.innerWidth, height: window.innerHeight}"
384
+
385
+ # Get screen resolution
386
+ chrome-cdp-cli eval "{width: screen.width, height: screen.height}"
387
+
388
+ # Get browser language
389
+ chrome-cdp-cli eval "navigator.language"
390
+
391
+ # Get cookies
392
+ chrome-cdp-cli eval "document.cookie"
393
+ ```
394
+
395
+ ### ⏳ Not Yet Implemented
396
+
397
+ These features require dedicated handlers and are not yet available:
398
+
399
+ - Native page management commands (new_page, close_page, list_pages, select_page)
400
+ - Native element interaction commands (click, hover, fill, drag)
401
+ - Native performance profiling commands
402
+ - Native device emulation commands
403
+ - Advanced output formatting options
404
+
405
+ ## The Power of Eval
406
+
407
+ The `eval` command is the most powerful feature of this CLI tool. It allows you to execute any JavaScript code in the browser context, making it possible to achieve almost any browser automation task. Here are some advanced examples:
408
+
409
+ ### Advanced Automation Examples
410
+
411
+ ```bash
412
+ # Wait for element to appear
413
+ chrome-cdp-cli eval "
414
+ new Promise(resolve => {
415
+ const check = () => {
416
+ const element = document.querySelector('#dynamic-content');
417
+ if (element) resolve(element.textContent);
418
+ else setTimeout(check, 100);
419
+ };
420
+ check();
421
+ })
422
+ "
423
+
424
+ # Scroll to element
425
+ chrome-cdp-cli eval "
426
+ document.querySelector('#target').scrollIntoView({behavior: 'smooth'});
427
+ "
428
+
429
+ # Take element screenshot (get element bounds for screenshot)
430
+ chrome-cdp-cli eval "
431
+ const element = document.querySelector('#target');
432
+ const rect = element.getBoundingClientRect();
433
+ ({x: rect.x, y: rect.y, width: rect.width, height: rect.height})
434
+ "
435
+
436
+ # Simulate complex user interactions
437
+ chrome-cdp-cli eval "
438
+ const element = document.querySelector('#button');
439
+ element.dispatchEvent(new MouseEvent('mousedown'));
440
+ setTimeout(() => element.dispatchEvent(new MouseEvent('mouseup')), 100);
441
+ "
442
+
443
+ # Extract structured data
444
+ chrome-cdp-cli eval "
445
+ Array.from(document.querySelectorAll('.product')).map(product => ({
446
+ name: product.querySelector('.name').textContent,
447
+ price: product.querySelector('.price').textContent,
448
+ image: product.querySelector('img').src
449
+ }))
450
+ "
451
+
452
+ # Monitor page changes
453
+ chrome-cdp-cli eval "
454
+ new Promise(resolve => {
455
+ const observer = new MutationObserver(mutations => {
456
+ resolve(mutations.length + ' changes detected');
457
+ observer.disconnect();
458
+ });
459
+ observer.observe(document.body, {childList: true, subtree: true});
460
+ setTimeout(() => {
461
+ observer.disconnect();
462
+ resolve('No changes in 5 seconds');
463
+ }, 5000);
464
+ })
465
+ "
466
+ ```
467
+
468
+ ## Current Limitations & Roadmap
469
+
470
+ ### Current Limitations
471
+
472
+ - **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
+ - **No performance profiling**: Advanced performance analysis requires manual JavaScript
475
+ - **No device emulation**: Mobile/tablet simulation not yet implemented
476
+ - **Basic output formatting**: Advanced JSON/text formatting options not available
477
+
478
+ ### Upcoming Features
479
+
480
+ 1. **Native Page Management Commands**
481
+ - `new_page`, `close_page`, `list_pages`, `select_page`
482
+ - Direct CDP Target domain integration
483
+
484
+ 2. **Native Element Interaction**
485
+ - `click`, `hover`, `fill`, `drag` commands
486
+ - CSS selector-based element targeting
487
+
488
+ 3. **Performance Analysis**
489
+ - `performance_start_trace`, `performance_stop_trace`
490
+ - Built-in performance metrics and analysis
491
+
492
+ 4. **Device Emulation**
493
+ - `emulate` command for device simulation
494
+ - Network condition simulation
495
+
496
+ 5. **Advanced Output Formatting**
497
+ - Enhanced JSON/text formatting
498
+ - Quiet and verbose modes
499
+ - Custom output templates
500
+
501
+ ### Why Use Eval Workarounds?
502
+
503
+ The eval approach offers several advantages:
504
+
505
+ - **Immediate availability**: No waiting for feature implementation
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
510
+
184
511
  ## Configuration
185
512
 
186
513
  ### Configuration File
@@ -17,6 +17,12 @@ class CLIApplication {
17
17
  this.cli.registerHandler(new handlers_1.EvaluateScriptHandler());
18
18
  this.cli.registerHandler(new handlers_1.TakeScreenshotHandler());
19
19
  this.cli.registerHandler(new handlers_1.TakeSnapshotHandler());
20
+ this.cli.registerHandler(new handlers_1.GetConsoleMessageHandler());
21
+ this.cli.registerHandler(new handlers_1.ListConsoleMessagesHandler());
22
+ this.cli.registerHandler(new handlers_1.GetNetworkRequestHandler());
23
+ this.cli.registerHandler(new handlers_1.ListNetworkRequestsHandler());
24
+ this.cli.registerHandler(new handlers_1.InstallCursorCommandHandler());
25
+ this.cli.registerHandler(new handlers_1.InstallClaudeSkillHandler());
20
26
  }
21
27
  async run(argv) {
22
28
  try {
@@ -35,7 +41,13 @@ class CLIApplication {
35
41
  }
36
42
  }
37
43
  needsConnection(commandName) {
38
- const noConnectionCommands = ['help', 'connect', 'disconnect'];
44
+ const noConnectionCommands = [
45
+ 'help',
46
+ 'connect',
47
+ 'disconnect',
48
+ 'install_cursor_command',
49
+ 'install_claude_skill'
50
+ ];
39
51
  return !noConnectionCommands.includes(commandName);
40
52
  }
41
53
  async ensureConnection(command) {
@@ -291,6 +291,26 @@ class CLIInterface {
291
291
  if (args[0])
292
292
  commandArgs.command = args[0];
293
293
  break;
294
+ case 'install_cursor_command':
295
+ if (options['target-directory'])
296
+ commandArgs.targetDirectory = options['target-directory'];
297
+ if (options['include-examples'] !== undefined)
298
+ commandArgs.includeExamples = options['include-examples'] !== 'false';
299
+ if (options['force'])
300
+ commandArgs.force = true;
301
+ break;
302
+ case 'install_claude_skill':
303
+ if (options['skill-type'])
304
+ commandArgs.skillType = options['skill-type'];
305
+ if (options['target-directory'])
306
+ commandArgs.targetDirectory = options['target-directory'];
307
+ if (options['include-examples'] !== undefined)
308
+ commandArgs.includeExamples = options['include-examples'] !== 'false';
309
+ if (options['include-references'] !== undefined)
310
+ commandArgs.includeReferences = options['include-references'] !== 'false';
311
+ if (options['force'])
312
+ commandArgs.force = true;
313
+ break;
294
314
  default:
295
315
  args.forEach((arg, index) => {
296
316
  commandArgs[`arg${index}`] = arg;
@@ -69,7 +69,13 @@ class CommandRouter {
69
69
  }
70
70
  }
71
71
  isSpecialCommand(commandName) {
72
- const specialCommands = ['help', 'connect', 'disconnect'];
72
+ const specialCommands = [
73
+ 'help',
74
+ 'connect',
75
+ 'disconnect',
76
+ 'install_cursor_command',
77
+ 'install_claude_skill'
78
+ ];
73
79
  return specialCommands.includes(commandName);
74
80
  }
75
81
  async executeSpecialCommand(command) {
@@ -80,6 +86,17 @@ class CommandRouter {
80
86
  return this.executeConnectCommand(command);
81
87
  case 'disconnect':
82
88
  return this.executeDisconnectCommand();
89
+ case 'install_cursor_command':
90
+ case 'install_claude_skill':
91
+ const handler = this.registry.get(command.name);
92
+ if (!handler) {
93
+ return {
94
+ success: false,
95
+ error: `Handler not found for command: ${command.name}`,
96
+ exitCode: ExitCode.INVALID_COMMAND
97
+ };
98
+ }
99
+ return await handler.execute(null, command.args);
83
100
  default:
84
101
  return {
85
102
  success: false,
@@ -229,6 +246,8 @@ For more information about a specific command, use:
229
246
  'snapshot': 'Capture DOM snapshot with structure and styles',
230
247
  'console-messages': 'Get console messages',
231
248
  'network-requests': 'Get network requests',
249
+ 'install_cursor_command': 'Install Cursor IDE commands for Chrome automation',
250
+ 'install_claude_skill': 'Install Claude Code skill for Chrome automation',
232
251
  'help': 'Show help information'
233
252
  };
234
253
  return descriptions[commandName] || 'No description available';
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetConsoleMessageHandler = void 0;
4
+ const ConsoleMonitor_1 = require("../monitors/ConsoleMonitor");
5
+ class GetConsoleMessageHandler {
6
+ constructor() {
7
+ this.name = 'get_console_message';
8
+ this.consoleMonitor = null;
9
+ }
10
+ async execute(client, args) {
11
+ try {
12
+ const params = args;
13
+ if (!this.consoleMonitor) {
14
+ this.consoleMonitor = new ConsoleMonitor_1.ConsoleMonitor(client);
15
+ }
16
+ if (params.startMonitoring || !this.consoleMonitor.isActive()) {
17
+ await this.consoleMonitor.startMonitoring();
18
+ }
19
+ const filter = {};
20
+ if (params.type) {
21
+ filter.types = [params.type];
22
+ }
23
+ if (params.textPattern) {
24
+ filter.textPattern = params.textPattern;
25
+ }
26
+ const latestMessage = this.consoleMonitor.getLatestMessage(filter);
27
+ if (!latestMessage) {
28
+ return {
29
+ success: true,
30
+ data: null
31
+ };
32
+ }
33
+ return {
34
+ success: true,
35
+ data: {
36
+ type: latestMessage.type,
37
+ text: latestMessage.text,
38
+ args: latestMessage.args,
39
+ timestamp: latestMessage.timestamp,
40
+ stackTrace: latestMessage.stackTrace
41
+ }
42
+ };
43
+ }
44
+ catch (error) {
45
+ return {
46
+ success: false,
47
+ error: error instanceof Error ? error.message : 'Unknown error occurred'
48
+ };
49
+ }
50
+ }
51
+ validateArgs(args) {
52
+ if (!args || typeof args !== 'object') {
53
+ return true;
54
+ }
55
+ const params = args;
56
+ if (params.type !== undefined) {
57
+ if (typeof params.type !== 'string') {
58
+ return false;
59
+ }
60
+ const validTypes = ['log', 'info', 'warn', 'error', 'debug'];
61
+ if (!validTypes.includes(params.type)) {
62
+ return false;
63
+ }
64
+ }
65
+ if (params.textPattern !== undefined && typeof params.textPattern !== 'string') {
66
+ return false;
67
+ }
68
+ if (params.startMonitoring !== undefined && typeof params.startMonitoring !== 'boolean') {
69
+ return false;
70
+ }
71
+ return true;
72
+ }
73
+ getHelp() {
74
+ return `get_console_message - Get the latest console message
75
+
76
+ Usage:
77
+ get_console_message [options]
78
+
79
+ Options:
80
+ --type <type> Filter by message type (log, info, warn, error, debug)
81
+ --textPattern <pattern> Filter by text pattern (regex)
82
+ --startMonitoring Start monitoring if not already active
83
+
84
+ Examples:
85
+ get_console_message
86
+ get_console_message --type error
87
+ get_console_message --textPattern "API"
88
+ get_console_message --startMonitoring`;
89
+ }
90
+ }
91
+ exports.GetConsoleMessageHandler = GetConsoleMessageHandler;