15

I'm using Google Chrome, and have a page that prints some information to the Javascript console - I want to pipe this to a script.

I've found how to display Chrome's stdout on OS X - by running the command below from a Terminal (a new user profile is needed to make sure the command spawns a new application, otherwise we'll open the existing one and get no output).

However, all I'm getting printed to Terminal is internal Chrome information.

Is there a way to get all JS console output to be printed to stdout/stderr so that I can pipe the output of the below command to my script?

TIA!

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir=temp-dir

Anthony
  • 173
  • 1
  • 7

1 Answers1

17
  • Enable logging from the command line using the flags:

    --enable-logging --v=stderr

This logs everything Chrome does internally, but it also logs all the console.log() messages as well. The log file is called chrome_debug.log and is located in the User Data Directory.

Tiago Fabre
  • 739
  • 5
  • 18
  • 7
    Not quite right, but your tip got me there, so thanks! If I enable logging **and** force a temp user directory (which I need to do on OS X, as mentioned before) then I don't see the output in the debug file you mentioned. On a hunch I went looking, and indeed there is a file `temp-dir/chrome_debug.log` which contains the output I want :) So the answere is `--enable-logging --v=1 --user-data-dir=temp-dir` to get what I need on OS X. – Anthony Aug 24 '16 at 16:08
  • 8
    `--enable-logging=stderr` is possible also – woprandi Jan 18 '18 at 10:20
  • 3
    Hey, do you know by chance how that would be for Firefox? – chitzui Jan 21 '19 at 10:09
  • 2
    The `chrome_debug.log` in this case will be full of data that do not appear on the console, which makes it impossible to parse. – gen Apr 15 '20 at 13:56
  • This works perfectly on a raspberry pi version 10 buster - this a debian. to view the log I used: sudo tail -f /rds/home/rds-user/.config/chromium/chrome_debug.log – c7borg Oct 11 '21 at 08:55