chrome-cdp-cli 1.8.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,683 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HelpSystem = void 0;
4
+ const CommandSchemaRegistry_1 = require("./CommandSchemaRegistry");
5
+ const colors = {
6
+ reset: '\x1b[0m',
7
+ bright: '\x1b[1m',
8
+ dim: '\x1b[2m',
9
+ red: '\x1b[31m',
10
+ green: '\x1b[32m',
11
+ yellow: '\x1b[33m',
12
+ blue: '\x1b[34m',
13
+ magenta: '\x1b[35m',
14
+ cyan: '\x1b[36m',
15
+ white: '\x1b[37m',
16
+ gray: '\x1b[90m',
17
+ };
18
+ const colorize = {
19
+ title: (text) => `${colors.bright}${colors.cyan}${text}${colors.reset}`,
20
+ section: (text) => `${colors.bright}${colors.blue}${text}${colors.reset}`,
21
+ command: (text) => `${colors.green}${text}${colors.reset}`,
22
+ alias: (text) => `${colors.gray}${text}${colors.reset}`,
23
+ option: (text) => `${colors.cyan}${text}${colors.reset}`,
24
+ description: (text) => text,
25
+ category: (text) => `${colors.bright}${colors.yellow}${text}${colors.reset}`,
26
+ };
27
+ class HelpSystem {
28
+ constructor(schemaRegistry, argumentParser) {
29
+ this.helpTopics = new Map();
30
+ this.contextualHelpers = new Map();
31
+ this.schemaRegistry = schemaRegistry || CommandSchemaRegistry_1.CommandSchemaRegistry.getInstance();
32
+ this.argumentParser = argumentParser;
33
+ this.initializeHelpTopics();
34
+ this.initializeContextualHelpers();
35
+ }
36
+ generateCommandHelp(commandName) {
37
+ let command;
38
+ if (this.argumentParser && this.argumentParser.getCommand) {
39
+ command = this.argumentParser.getCommand(commandName);
40
+ }
41
+ if (!command) {
42
+ command = this.schemaRegistry.getCommand(commandName);
43
+ }
44
+ if (!command) {
45
+ return this.generateCommandNotFoundHelp(commandName);
46
+ }
47
+ let help = '';
48
+ help += `${command.name.toUpperCase()}\n`;
49
+ help += '='.repeat(command.name.length) + '\n\n';
50
+ help += `${command.description}\n\n`;
51
+ if (command.usage) {
52
+ help += 'USAGE\n';
53
+ help += '-----\n';
54
+ help += `${command.usage}\n\n`;
55
+ }
56
+ if (command.arguments.length > 0) {
57
+ help += 'ARGUMENTS\n';
58
+ help += '---------\n';
59
+ for (const arg of command.arguments) {
60
+ const required = arg.required ? ' (required)' : ' (optional)';
61
+ const variadic = arg.variadic ? '...' : '';
62
+ help += ` ${arg.name}${variadic}${required.padStart(30 - arg.name.length - variadic.length)}\n`;
63
+ help += ` ${arg.description}\n`;
64
+ if (arg.type !== 'string') {
65
+ help += ` Type: ${arg.type}\n`;
66
+ }
67
+ help += '\n';
68
+ }
69
+ }
70
+ if (command.options.length > 0) {
71
+ help += 'OPTIONS\n';
72
+ help += '-------\n';
73
+ for (const option of command.options) {
74
+ const shortFlag = option.short ? `-${option.short}, ` : ' ';
75
+ const longFlag = `--${option.name}`;
76
+ const negation = option.type === 'boolean' ? `, --no-${option.name}` : '';
77
+ const flags = `${shortFlag}${longFlag}${negation}`;
78
+ help += ` ${flags}\n`;
79
+ help += ` ${option.description}\n`;
80
+ if (option.type !== 'string') {
81
+ help += ` Type: ${option.type}\n`;
82
+ }
83
+ if (option.required) {
84
+ help += ` Required: yes\n`;
85
+ }
86
+ if (option.default !== undefined) {
87
+ help += ` Default: ${option.default}\n`;
88
+ }
89
+ if (option.choices && option.choices.length > 0) {
90
+ help += ` Choices: ${option.choices.join(', ')}\n`;
91
+ }
92
+ help += '\n';
93
+ }
94
+ }
95
+ if (command.examples && command.examples.length > 0) {
96
+ help += 'EXAMPLES\n';
97
+ help += '--------\n';
98
+ for (let i = 0; i < command.examples.length; i++) {
99
+ const example = command.examples[i];
100
+ help += `${i + 1}. ${example.description || 'Example usage'}\n`;
101
+ help += ` $ ${example.command}\n\n`;
102
+ }
103
+ }
104
+ if (command.aliases.length > 0) {
105
+ help += 'ALIASES\n';
106
+ help += '-------\n';
107
+ help += `${command.aliases.join(', ')}\n\n`;
108
+ }
109
+ const relatedTopics = this.getRelatedHelpTopics(commandName);
110
+ if (relatedTopics.length > 0) {
111
+ help += 'SEE ALSO\n';
112
+ help += '--------\n';
113
+ help += `Help topics: ${relatedTopics.join(', ')}\n`;
114
+ help += `Use 'chrome-cdp-cli help topic <topic-name>' for more information\n\n`;
115
+ }
116
+ return help.trim();
117
+ }
118
+ generateGeneralHelp() {
119
+ let help = '';
120
+ help += `${colorize.title('CHROME DEVTOOLS CLI - ENHANCED HELP SYSTEM')}\n`;
121
+ help += `${colors.cyan}${'='.repeat(42)}${colors.reset}\n\n`;
122
+ help += 'A powerful command-line interface for Chrome DevTools Protocol automation.\n\n';
123
+ help += `${colorize.section('USAGE')}\n`;
124
+ help += `${colors.blue}${'-'.repeat(5)}${colors.reset}\n`;
125
+ help += `${colorize.command('chrome-cdp-cli')} [global-options] <command> [command-options] [arguments]\n\n`;
126
+ help += `${colorize.section('GLOBAL OPTIONS')}\n`;
127
+ help += `${colors.blue}${'-'.repeat(15)}${colors.reset}\n`;
128
+ help += ` ${colorize.option('-h, --host <host>')} Chrome host address (default: localhost)\n`;
129
+ help += ` ${colorize.option('-p, --port <port>')} DevTools port (default: 9222)\n`;
130
+ help += ` ${colorize.option('-f, --format <format>')} Output format: json|text (default: text)\n`;
131
+ help += ` ${colorize.option('-v, --verbose')} Enable verbose logging\n`;
132
+ help += ` ${colorize.option('--no-verbose')} Disable verbose logging\n`;
133
+ help += ` ${colorize.option('-q, --quiet')} Enable quiet mode\n`;
134
+ help += ` ${colorize.option('--no-quiet')} Disable quiet mode\n`;
135
+ help += ` ${colorize.option('-t, --timeout <ms>')} Command timeout in milliseconds (default: 30000)\n`;
136
+ help += ` ${colorize.option('-d, --debug')} Enable debug logging\n`;
137
+ help += ` ${colorize.option('--no-debug')} Disable debug logging\n`;
138
+ help += ` ${colorize.option('-c, --config <path>')} Configuration file path\n`;
139
+ help += ` ${colorize.option('--version')} Show version number\n\n`;
140
+ let commands;
141
+ if (this.argumentParser && this.argumentParser.getCommands) {
142
+ commands = this.argumentParser.getCommands();
143
+ }
144
+ else {
145
+ commands = this.schemaRegistry.getAllCommands();
146
+ }
147
+ const categorizedCommands = this.categorizeCommands(commands);
148
+ help += `${colorize.section('AVAILABLE COMMANDS')}\n`;
149
+ help += `${colors.blue}${'-'.repeat(18)}${colors.reset}\n`;
150
+ for (const [categoryName, categoryCommands] of categorizedCommands) {
151
+ help += `\n${colorize.category(categoryName)}:\n`;
152
+ for (const command of categoryCommands) {
153
+ const commandName = colorize.command(command.name);
154
+ const aliases = command.aliases.length > 0 ? ` ${colorize.alias(`(${command.aliases.join(', ')})`)}` : '';
155
+ const namePadding = Math.max(0, 20 - command.name.length);
156
+ const aliasText = command.aliases.length > 0 ? `(${command.aliases.join(', ')})` : '';
157
+ const aliasPadding = Math.max(0, 15 - aliasText.length);
158
+ help += ` ${commandName}${' '.repeat(namePadding)}${aliases}${' '.repeat(aliasPadding)} ${command.description}\n`;
159
+ }
160
+ }
161
+ help += `\n${colorize.section('GETTING MORE HELP')}\n`;
162
+ help += `${colors.blue}${'-'.repeat(18)}${colors.reset}\n`;
163
+ help += 'For detailed help on a specific command:\n';
164
+ help += ` ${colorize.command('chrome-cdp-cli')} ${colorize.option('help')} <command>\n\n`;
165
+ help += 'For contextual help when commands fail:\n';
166
+ help += ' Commands automatically show relevant help suggestions on errors\n\n';
167
+ return help.trim();
168
+ }
169
+ generateTopicHelp(topicName) {
170
+ const topic = this.helpTopics.get(topicName);
171
+ if (!topic) {
172
+ return this.generateTopicNotFoundHelp(topicName);
173
+ }
174
+ let help = '';
175
+ help += `${topic.title.toUpperCase()}\n`;
176
+ help += '='.repeat(topic.title.length) + '\n\n';
177
+ help += `${topic.content}\n\n`;
178
+ if (topic.examples && topic.examples.length > 0) {
179
+ help += 'EXAMPLES\n';
180
+ help += '--------\n';
181
+ for (let i = 0; i < topic.examples.length; i++) {
182
+ help += `${i + 1}. ${topic.examples[i]}\n`;
183
+ }
184
+ help += '\n';
185
+ }
186
+ if (topic.seeAlso && topic.seeAlso.length > 0) {
187
+ help += 'SEE ALSO\n';
188
+ help += '--------\n';
189
+ help += `${topic.seeAlso.join(', ')}\n\n`;
190
+ }
191
+ return help.trim();
192
+ }
193
+ generateContextualHelp(error, commandName) {
194
+ let help = '';
195
+ const suggestions = this.findContextualSuggestions(error, commandName);
196
+ if (suggestions.length === 0) {
197
+ help += 'HELP SUGGESTIONS\n';
198
+ help += '----------------\n';
199
+ help += 'No specific suggestions available for this error.\n\n';
200
+ help += 'Try:\n';
201
+ help += ' - Check command syntax with: chrome-cdp-cli help <command>\n';
202
+ help += ' - Verify Chrome is running with --remote-debugging-port=9222\n';
203
+ help += ' - Use --debug flag for detailed error information\n\n';
204
+ }
205
+ else {
206
+ help += 'HELP SUGGESTIONS\n';
207
+ help += '----------------\n';
208
+ for (let i = 0; i < suggestions.length; i++) {
209
+ const suggestion = suggestions[i];
210
+ help += `${i + 1}. ${suggestion.suggestion}\n`;
211
+ if (suggestion.example) {
212
+ help += ` Example: ${suggestion.example}\n`;
213
+ }
214
+ if (suggestion.relatedCommands && suggestion.relatedCommands.length > 0) {
215
+ help += ` Related commands: ${suggestion.relatedCommands.join(', ')}\n`;
216
+ }
217
+ help += '\n';
218
+ }
219
+ }
220
+ if (commandName) {
221
+ help += `For detailed help on '${commandName}' command:\n`;
222
+ help += ` chrome-cdp-cli help ${commandName}\n\n`;
223
+ }
224
+ return help.trim();
225
+ }
226
+ generateCommandNotFoundHelp(commandName) {
227
+ let help = '';
228
+ help += `ERROR: Unknown command '${commandName}'\n\n`;
229
+ const similarCommands = this.findSimilarCommands(commandName);
230
+ if (similarCommands.length > 0) {
231
+ help += 'Did you mean:\n';
232
+ for (const similar of similarCommands) {
233
+ help += ` ${similar}\n`;
234
+ }
235
+ help += '\n';
236
+ }
237
+ help += 'Available commands:\n';
238
+ let commands;
239
+ if (this.argumentParser && this.argumentParser.getCommands) {
240
+ commands = this.argumentParser.getCommands();
241
+ }
242
+ else {
243
+ commands = this.schemaRegistry.getAllCommands();
244
+ }
245
+ for (const command of commands.sort((a, b) => a.name.localeCompare(b.name))) {
246
+ help += ` ${command.name.padEnd(20)} ${command.description}\n`;
247
+ }
248
+ help += '\nFor more information:\n';
249
+ help += ' chrome-cdp-cli help\n';
250
+ return help;
251
+ }
252
+ generateTopicNotFoundHelp(topicName) {
253
+ let help = '';
254
+ help += `ERROR: Unknown help topic '${topicName}'\n\n`;
255
+ help += 'Available help topics:\n';
256
+ const topics = Array.from(this.helpTopics.values()).sort((a, b) => a.name.localeCompare(b.name));
257
+ for (const topic of topics) {
258
+ help += ` ${topic.name.padEnd(20)} ${topic.description}\n`;
259
+ }
260
+ help += '\nUsage:\n';
261
+ help += ' chrome-cdp-cli help topic <topic-name>\n';
262
+ return help;
263
+ }
264
+ findSimilarCommands(commandName) {
265
+ let commands;
266
+ if (this.argumentParser && this.argumentParser.getCommands) {
267
+ commands = this.argumentParser.getCommands();
268
+ }
269
+ else {
270
+ commands = this.schemaRegistry.getAllCommands();
271
+ }
272
+ const similar = [];
273
+ for (const command of commands) {
274
+ if (command.name.includes(commandName) || commandName.includes(command.name)) {
275
+ similar.push(command.name);
276
+ }
277
+ for (const alias of command.aliases) {
278
+ if (alias.includes(commandName) || commandName.includes(alias)) {
279
+ similar.push(command.name);
280
+ break;
281
+ }
282
+ }
283
+ }
284
+ return [...new Set(similar)].slice(0, 5);
285
+ }
286
+ findContextualSuggestions(error, commandName) {
287
+ const suggestions = [];
288
+ for (const [errorPattern, helpers] of this.contextualHelpers) {
289
+ if (error.toLowerCase().includes(errorPattern.toLowerCase())) {
290
+ suggestions.push(...helpers);
291
+ }
292
+ }
293
+ if (commandName) {
294
+ const commandHelpers = this.contextualHelpers.get(`command:${commandName}`);
295
+ if (commandHelpers) {
296
+ suggestions.push(...commandHelpers);
297
+ }
298
+ }
299
+ return suggestions;
300
+ }
301
+ categorizeCommands(commands) {
302
+ const categories = new Map();
303
+ for (const command of commands) {
304
+ let category = 'General';
305
+ if (['eval', 'execute', 'js'].includes(command.name)) {
306
+ category = 'JavaScript Execution';
307
+ }
308
+ else if (['screenshot', 'capture', 'snapshot', 'dom'].includes(command.name)) {
309
+ category = 'Page Capture';
310
+ }
311
+ else if (['click', 'hover', 'fill', 'type', 'drag', 'press', 'upload'].includes(command.name)) {
312
+ category = 'User Interaction';
313
+ }
314
+ else if (['console', 'network', 'logs', 'requests'].includes(command.name) ||
315
+ command.name.includes('console') || command.name.includes('network')) {
316
+ category = 'Monitoring & Debugging';
317
+ }
318
+ else if (['navigate', 'goto', 'open', 'wait'].includes(command.name)) {
319
+ category = 'Navigation & Timing';
320
+ }
321
+ else if (command.name.includes('install')) {
322
+ category = 'Installation & Setup';
323
+ }
324
+ else if (['help', 'version'].includes(command.name)) {
325
+ category = 'Help & Information';
326
+ }
327
+ if (!categories.has(category)) {
328
+ categories.set(category, []);
329
+ }
330
+ categories.get(category).push(command);
331
+ }
332
+ for (const [, categoryCommands] of categories) {
333
+ categoryCommands.sort((a, b) => a.name.localeCompare(b.name));
334
+ }
335
+ return categories;
336
+ }
337
+ getRelatedHelpTopics(commandName) {
338
+ const related = [];
339
+ const topicMappings = {
340
+ 'eval': ['configuration', 'scripting'],
341
+ 'screenshot': ['configuration', 'output-formats'],
342
+ 'click': ['selectors', 'automation'],
343
+ 'fill': ['selectors', 'automation'],
344
+ 'hover': ['selectors', 'automation'],
345
+ 'console_messages': ['monitoring', 'debugging'],
346
+ 'network_requests': ['monitoring', 'debugging'],
347
+ 'install_cursor_command': ['installation', 'integration'],
348
+ 'install_claude_skill': ['installation', 'integration']
349
+ };
350
+ const mappedTopics = topicMappings[commandName];
351
+ if (mappedTopics) {
352
+ for (const topic of mappedTopics) {
353
+ if (this.helpTopics.has(topic)) {
354
+ related.push(topic);
355
+ }
356
+ }
357
+ }
358
+ return related;
359
+ }
360
+ initializeHelpTopics() {
361
+ this.helpTopics.set('configuration', {
362
+ name: 'configuration',
363
+ title: 'Configuration Management',
364
+ description: 'Advanced configuration options and file formats',
365
+ content: `The Chrome DevTools CLI supports multiple configuration sources with a clear precedence order:
366
+
367
+ 1. Command-line arguments (highest priority)
368
+ 2. Environment variables
369
+ 3. Configuration files (profile-specific, then default)
370
+ 4. Default values (lowest priority)
371
+
372
+ Configuration files can be in YAML or JSON format and support:
373
+ - Global default settings
374
+ - Profile-specific configurations
375
+ - Command-specific defaults
376
+ - Plugin configurations
377
+ - Custom aliases
378
+
379
+ Environment variables follow the pattern CDP_<OPTION_NAME> (e.g., CDP_HOST, CDP_PORT).`,
380
+ examples: [
381
+ 'chrome-cdp-cli --config ~/.chrome-cdp-cli.yaml eval "document.title"',
382
+ 'CDP_HOST=remote-chrome CDP_PORT=9223 chrome-cdp-cli screenshot',
383
+ 'chrome-cdp-cli --profile production screenshot --full-page'
384
+ ],
385
+ seeAlso: ['profiles', 'environment-variables']
386
+ });
387
+ this.helpTopics.set('selectors', {
388
+ name: 'selectors',
389
+ title: 'CSS Selectors Guide',
390
+ description: 'Guide to using CSS selectors effectively',
391
+ content: `CSS selectors are used to target elements for interaction commands like click, fill, and hover.
392
+
393
+ Supported selector types:
394
+ - ID selectors: #element-id
395
+ - Class selectors: .class-name
396
+ - Attribute selectors: [data-testid="value"]
397
+ - Pseudo-selectors: :first-child, :nth-of-type(2)
398
+ - Complex selectors: .parent > .child, .item:not(.disabled)
399
+
400
+ Best practices:
401
+ - Use data-testid attributes for reliable automation
402
+ - Prefer specific selectors over generic ones
403
+ - Test selectors in browser DevTools first
404
+ - Use :visible pseudo-selector for visible elements only`,
405
+ examples: [
406
+ 'chrome-cdp-cli click "#submit-button"',
407
+ 'chrome-cdp-cli fill "[data-testid=username]" "user@example.com"',
408
+ 'chrome-cdp-cli hover ".dropdown-menu > .first-item"'
409
+ ],
410
+ seeAlso: ['automation', 'debugging']
411
+ });
412
+ this.helpTopics.set('automation', {
413
+ name: 'automation',
414
+ title: 'Browser Automation Best Practices',
415
+ description: 'Guidelines for effective browser automation',
416
+ content: `Effective browser automation requires careful planning and robust selectors.
417
+
418
+ Key principles:
419
+ - Wait for elements to be ready before interaction
420
+ - Use explicit waits instead of arbitrary delays
421
+ - Handle dynamic content and loading states
422
+ - Implement proper error handling and retries
423
+ - Use page object patterns for complex workflows
424
+
425
+ Common patterns:
426
+ - Navigate → Wait → Interact → Verify
427
+ - Fill forms step by step with validation
428
+ - Take screenshots for debugging failed tests
429
+ - Monitor console and network for errors`,
430
+ examples: [
431
+ 'chrome-cdp-cli navigate "https://example.com" && chrome-cdp-cli wait "#content" && chrome-cdp-cli click ".login"',
432
+ 'chrome-cdp-cli fill "#username" "user" && chrome-cdp-cli fill "#password" "pass" && chrome-cdp-cli click "#login"'
433
+ ],
434
+ seeAlso: ['selectors', 'debugging', 'scripting']
435
+ });
436
+ this.helpTopics.set('output-formats', {
437
+ name: 'output-formats',
438
+ title: 'Output Formats and Processing',
439
+ description: 'Understanding different output formats and processing options',
440
+ content: `The CLI supports multiple output formats for different use cases:
441
+
442
+ Text format (default):
443
+ - Human-readable output
444
+ - Formatted for console display
445
+ - Includes contextual information
446
+
447
+ JSON format:
448
+ - Machine-parseable structured data
449
+ - Suitable for scripting and automation
450
+ - Preserves all data fields and metadata
451
+
452
+ Quiet mode:
453
+ - Suppresses non-essential output
454
+ - Shows only errors and critical information
455
+ - Useful for automated scripts
456
+
457
+ Verbose mode:
458
+ - Includes detailed operation information
459
+ - Shows timing and performance data
460
+ - Helpful for debugging and optimization`,
461
+ examples: [
462
+ 'chrome-cdp-cli --format json eval "document.title"',
463
+ 'chrome-cdp-cli --quiet screenshot --filename result.png',
464
+ 'chrome-cdp-cli --verbose --debug console_messages'
465
+ ],
466
+ seeAlso: ['configuration', 'scripting']
467
+ });
468
+ this.helpTopics.set('debugging', {
469
+ name: 'debugging',
470
+ title: 'Debugging and Troubleshooting',
471
+ description: 'Tools and techniques for debugging CLI issues',
472
+ content: `When commands don't work as expected, use these debugging techniques:
473
+
474
+ Debug mode (--debug):
475
+ - Shows detailed execution logs
476
+ - Includes stack traces for errors
477
+ - Displays CDP protocol messages
478
+
479
+ Verbose mode (--verbose):
480
+ - Shows timing information
481
+ - Includes connection details
482
+ - Displays intermediate results
483
+
484
+ Common issues and solutions:
485
+ - Connection refused: Check Chrome is running with --remote-debugging-port=9222
486
+ - Element not found: Verify selectors in browser DevTools
487
+ - Timeout errors: Increase timeout or wait for page load
488
+ - Permission denied: Check file paths and permissions
489
+
490
+ Monitoring commands:
491
+ - Use console_messages to check for JavaScript errors
492
+ - Use network_requests to verify API calls
493
+ - Take screenshots to see current page state`,
494
+ examples: [
495
+ 'chrome-cdp-cli --debug --verbose click "#button"',
496
+ 'chrome-cdp-cli console_messages --filter error',
497
+ 'chrome-cdp-cli screenshot --filename debug.png'
498
+ ],
499
+ seeAlso: ['monitoring', 'automation']
500
+ });
501
+ this.helpTopics.set('scripting', {
502
+ name: 'scripting',
503
+ title: 'Scripting and Integration',
504
+ description: 'Using the CLI in scripts and automation workflows',
505
+ content: `The CLI is designed for integration with shell scripts, CI/CD pipelines, and automation tools.
506
+
507
+ Shell scripting tips:
508
+ - Check exit codes for error handling
509
+ - Use --format json for parsing results
510
+ - Combine commands with && for sequential execution
511
+ - Use --quiet mode to reduce noise
512
+
513
+ Error handling:
514
+ - Exit code 0: Success
515
+ - Exit code 1: General error
516
+ - Exit code 2: Connection error
517
+ - Exit code 3: Command not found
518
+ - Exit code 4: Invalid arguments
519
+ - Exit code 5: Validation error
520
+
521
+ CI/CD integration:
522
+ - Set CDP_HOST and CDP_PORT environment variables
523
+ - Use configuration files for consistent settings
524
+ - Capture screenshots on test failures
525
+ - Monitor console errors in automated tests`,
526
+ examples: [
527
+ '#!/bin/bash\nif chrome-cdp-cli eval "document.readyState === \'complete\'"; then\n chrome-cdp-cli screenshot\nfi',
528
+ 'chrome-cdp-cli --format json eval "performance.timing" | jq .data.loadEventEnd'
529
+ ],
530
+ seeAlso: ['configuration', 'output-formats']
531
+ });
532
+ this.helpTopics.set('installation', {
533
+ name: 'installation',
534
+ title: 'Installation and Setup',
535
+ description: 'Setting up the CLI and integrations',
536
+ content: `The CLI can be integrated with various development tools and IDEs.
537
+
538
+ Chrome setup:
539
+ - Start Chrome with: --remote-debugging-port=9222
540
+ - For headless mode: --headless --disable-gpu
541
+ - For automation: --no-sandbox --disable-dev-shm-usage
542
+
543
+ IDE integrations:
544
+ - Cursor IDE: Use install_cursor_command for custom commands
545
+ - Claude Code: Use install_claude_skill for AI assistance
546
+ - VS Code: Create custom tasks and snippets
547
+
548
+ Configuration setup:
549
+ - Create ~/.chrome-cdp-cli.yaml for global settings
550
+ - Use project-specific .chrome-cdp-cli.yaml files
551
+ - Set up environment variables for CI/CD
552
+
553
+ Plugin development:
554
+ - Follow the plugin API specification
555
+ - Register commands with proper schemas
556
+ - Include comprehensive help documentation`,
557
+ examples: [
558
+ 'chrome --remote-debugging-port=9222 --headless',
559
+ 'chrome-cdp-cli install_cursor_command --target-directory ./commands',
560
+ 'chrome-cdp-cli install_claude_skill --skill-type automation'
561
+ ],
562
+ seeAlso: ['configuration', 'integration']
563
+ });
564
+ }
565
+ initializeContextualHelpers() {
566
+ this.contextualHelpers.set('connection refused', [
567
+ {
568
+ error: 'connection refused',
569
+ suggestion: 'Make sure Chrome is running with remote debugging enabled',
570
+ example: 'chrome --remote-debugging-port=9222',
571
+ relatedCommands: ['help']
572
+ },
573
+ {
574
+ error: 'connection refused',
575
+ suggestion: 'Check if the host and port are correct',
576
+ example: 'chrome-cdp-cli --host localhost --port 9222 <command>',
577
+ relatedCommands: ['help']
578
+ }
579
+ ]);
580
+ this.contextualHelpers.set('element not found', [
581
+ {
582
+ error: 'element not found',
583
+ suggestion: 'Verify the CSS selector in browser DevTools',
584
+ example: 'Open DevTools → Console → document.querySelector("#your-selector")',
585
+ relatedCommands: ['help topic selectors']
586
+ },
587
+ {
588
+ error: 'element not found',
589
+ suggestion: 'Wait for the page to load completely before interacting',
590
+ example: 'chrome-cdp-cli wait "#element" && chrome-cdp-cli click "#element"',
591
+ relatedCommands: ['wait']
592
+ }
593
+ ]);
594
+ this.contextualHelpers.set('timeout', [
595
+ {
596
+ error: 'timeout',
597
+ suggestion: 'Increase the timeout value for slow operations',
598
+ example: 'chrome-cdp-cli --timeout 60000 <command>',
599
+ relatedCommands: ['help']
600
+ },
601
+ {
602
+ error: 'timeout',
603
+ suggestion: 'Check if the page is loading or if there are network issues',
604
+ example: 'chrome-cdp-cli console_messages --filter error',
605
+ relatedCommands: ['console_messages', 'network_requests']
606
+ }
607
+ ]);
608
+ this.contextualHelpers.set('parse error', [
609
+ {
610
+ error: 'parse error',
611
+ suggestion: 'Check command syntax and argument order',
612
+ example: 'chrome-cdp-cli help <command-name>',
613
+ relatedCommands: ['help']
614
+ },
615
+ {
616
+ error: 'parse error',
617
+ suggestion: 'Use quotes around arguments containing spaces or special characters',
618
+ example: 'chrome-cdp-cli eval "document.querySelector(\'.my-class\')"',
619
+ relatedCommands: ['help topic scripting']
620
+ }
621
+ ]);
622
+ this.contextualHelpers.set('validation failed', [
623
+ {
624
+ error: 'validation failed',
625
+ suggestion: 'Check required arguments and option types',
626
+ example: 'chrome-cdp-cli help <command-name>',
627
+ relatedCommands: ['help']
628
+ },
629
+ {
630
+ error: 'validation failed',
631
+ suggestion: 'Ensure file paths exist and URLs are valid',
632
+ example: 'ls -la /path/to/file.js',
633
+ relatedCommands: ['help topic debugging']
634
+ }
635
+ ]);
636
+ this.contextualHelpers.set('permission denied', [
637
+ {
638
+ error: 'permission denied',
639
+ suggestion: 'Check file permissions and directory access',
640
+ example: 'chmod +r /path/to/file',
641
+ relatedCommands: ['help topic debugging']
642
+ },
643
+ {
644
+ error: 'permission denied',
645
+ suggestion: 'Ensure the target directory exists and is writable',
646
+ example: 'mkdir -p /path/to/directory && chmod +w /path/to/directory',
647
+ relatedCommands: ['help topic installation']
648
+ }
649
+ ]);
650
+ this.contextualHelpers.set('command:eval', [
651
+ {
652
+ error: 'eval',
653
+ suggestion: 'Use proper JavaScript syntax and escape quotes',
654
+ example: 'chrome-cdp-cli eval "document.querySelector(\\"#id\\").textContent"',
655
+ relatedCommands: ['help eval', 'help topic scripting']
656
+ }
657
+ ]);
658
+ this.contextualHelpers.set('command:screenshot', [
659
+ {
660
+ error: 'screenshot',
661
+ suggestion: 'Ensure the output directory exists and is writable',
662
+ example: 'mkdir -p screenshots && chrome-cdp-cli screenshot --filename screenshots/page.png',
663
+ relatedCommands: ['help screenshot']
664
+ }
665
+ ]);
666
+ }
667
+ getAvailableTopics() {
668
+ return Array.from(this.helpTopics.keys()).sort();
669
+ }
670
+ hasHelpTopic(topicName) {
671
+ return this.helpTopics.has(topicName);
672
+ }
673
+ addHelpTopic(topic) {
674
+ this.helpTopics.set(topic.name, topic);
675
+ }
676
+ addContextualHelp(errorPattern, help) {
677
+ if (!this.contextualHelpers.has(errorPattern)) {
678
+ this.contextualHelpers.set(errorPattern, []);
679
+ }
680
+ this.contextualHelpers.get(errorPattern).push(help);
681
+ }
682
+ }
683
+ exports.HelpSystem = HelpSystem;