chrome-cdp-cli 1.8.0 → 1.9.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
@@ -119,7 +119,7 @@ npm link
119
119
  Before using the CLI, start Chrome with remote debugging enabled:
120
120
 
121
121
  ```bash
122
- # Default port (9222) - IMPORTANT: Include --user-data-dir to avoid conflicts
122
+ # Default port (9222) - IMPORTANT: --user-data-dir is required for security
123
123
  chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug-profile
124
124
 
125
125
  # Custom port
@@ -136,9 +136,9 @@ chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug-profile --
136
136
  ```
137
137
 
138
138
  **Important Notes:**
139
- - **Always use `--user-data-dir`**: This creates a separate Chrome profile for debugging and prevents conflicts with your regular Chrome instance
139
+ - **Always use `--user-data-dir`**: This is **required for security**. Chrome will not enable the debugging port without a specified user data directory to prevent unauthorized access to your default profile
140
140
  - **Choose a dedicated directory**: Use a path like `/tmp/chrome-debug-profile` or `/Users/$USER/chrome-profile-debug`
141
- - **Avoid profile conflicts**: Without `--user-data-dir`, Chrome may fail to open the debugging port if another instance is running
141
+ - **Security requirement**: Without `--user-data-dir`, Chrome will refuse to enable remote debugging to protect your default browser profile
142
142
 
143
143
  For more details, see the [Chrome Remote Debugging documentation](https://developer.chrome.com/blog/remote-debugging-port).
144
144
 
@@ -910,7 +910,7 @@ Create a `.chrome-cdp-cli.json` file in your project root or home directory:
910
910
 
911
911
  ```bash
912
912
  # Clone repository
913
- git clone https://github.com/nickxiao42/chrome-devtools-cli.git
913
+ git clone https://github.com/nicoster/chrome-devtools-cli.git
914
914
  cd chrome-devtools-cli
915
915
 
916
916
  # Install dependencies
@@ -1030,14 +1030,14 @@ console.log(result);
1030
1030
 
1031
1031
  1. **Connection Refused**
1032
1032
  - Ensure Chrome is running with `--remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug`
1033
- - **Always include `--user-data-dir`** to avoid profile conflicts
1033
+ - **Always include `--user-data-dir`** - it's required for security (Chrome won't enable debugging port without it)
1034
1034
  - Check if the port is correct and not blocked by firewall
1035
1035
  - Verify no other Chrome instances are using the same debugging port
1036
1036
 
1037
1037
  2. **Chrome Won't Start Debugging Port**
1038
1038
  - **Most common cause**: Missing `--user-data-dir` parameter
1039
1039
  - **Solution**: Use a dedicated profile directory: `--user-data-dir=/tmp/chrome-debug-profile`
1040
- - **Why needed**: Prevents conflicts with existing Chrome instances
1040
+ - **Why needed**: Chrome requires `--user-data-dir` for security - it will not enable the debugging port without it to protect your default browser profile
1041
1041
  - See [Chrome Remote Debugging documentation](https://developer.chrome.com/blog/remote-debugging-port) for details
1042
1042
 
1043
1043
  3. **Command Timeout**
@@ -159,7 +159,7 @@ class EvaluateScriptHandler {
159
159
  }
160
160
  let value = commandResult.result?.value;
161
161
  if (commandResult.result?.type === 'undefined') {
162
- value = undefined;
162
+ value = '';
163
163
  }
164
164
  else if (commandResult.result?.unserializableValue) {
165
165
  value = commandResult.result.unserializableValue;
@@ -227,6 +227,10 @@ class EvaluateScriptHandler {
227
227
  }
228
228
  }
229
229
  async executeScript(client, expression, awaitPromise, returnByValue) {
230
+ const consoleHandler = (params) => {
231
+ this.handleConsoleOutput(params);
232
+ };
233
+ client.on('Runtime.consoleAPICalled', consoleHandler);
230
234
  try {
231
235
  const response = (await client.send('Runtime.evaluate', {
232
236
  expression,
@@ -261,6 +265,52 @@ class EvaluateScriptHandler {
261
265
  error: `CDP command failed: ${error instanceof Error ? error.message : String(error)}`
262
266
  };
263
267
  }
268
+ finally {
269
+ client.off('Runtime.consoleAPICalled', consoleHandler);
270
+ }
271
+ }
272
+ handleConsoleOutput(params) {
273
+ try {
274
+ const consoleParams = params;
275
+ const messageText = this.formatConsoleArgs(consoleParams.args || []);
276
+ const messageType = this.mapConsoleType(consoleParams.type);
277
+ if (messageType === 'log' || messageType === 'info' || messageType === 'debug') {
278
+ process.stdout.write(messageText + '\n');
279
+ }
280
+ else {
281
+ process.stderr.write(messageText + '\n');
282
+ }
283
+ }
284
+ catch (error) {
285
+ this.logger.debug('Error handling console output:', error);
286
+ }
287
+ }
288
+ formatConsoleArgs(args) {
289
+ return args.map(arg => {
290
+ if (arg.value !== undefined) {
291
+ if (typeof arg.value === 'string') {
292
+ return arg.value;
293
+ }
294
+ return JSON.stringify(arg.value);
295
+ }
296
+ return arg.description || '';
297
+ }).join(' ');
298
+ }
299
+ mapConsoleType(cdpType) {
300
+ switch (cdpType) {
301
+ case 'log':
302
+ return 'log';
303
+ case 'info':
304
+ return 'info';
305
+ case 'warning':
306
+ return 'warn';
307
+ case 'error':
308
+ return 'error';
309
+ case 'debug':
310
+ return 'debug';
311
+ default:
312
+ return 'log';
313
+ }
264
314
  }
265
315
  formatException(exceptionDetails) {
266
316
  if (!exceptionDetails) {
@@ -285,7 +335,10 @@ class EvaluateScriptHandler {
285
335
  }
286
336
  formatResult(result) {
287
337
  if (!result) {
288
- return 'undefined';
338
+ return '';
339
+ }
340
+ if (result.type === 'undefined') {
341
+ return '';
289
342
  }
290
343
  if (result.value !== undefined) {
291
344
  return result.value;
@@ -52,7 +52,7 @@ class Logger {
52
52
  maxFileSize: 10 * 1024 * 1024,
53
53
  maxFiles: 5,
54
54
  enableConsole: true,
55
- enableStructured: true,
55
+ enableStructured: false,
56
56
  ...config
57
57
  };
58
58
  if (this.config.file) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chrome-cdp-cli",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Browser automation CLI via Chrome DevTools Protocol. Designed for developers and AI assistants - combines dedicated commands for common tasks with flexible JavaScript execution for complex scenarios. Features: element interaction, screenshots, DOM snapshots, console/network monitoring. Built-in IDE integration for Cursor and Claude.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",