chrome-cdp-cli 1.8.1 → 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.
@@ -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.1",
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",