Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Chrome, how can I get the javascript console output to stdout/stderr

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

like image 211
Anthony Avatar asked Aug 23 '16 11:08

Anthony


People also ask

How to open Chrome JavaScript Console in chrome?

In Chrome JavaScript Console is open by navigating to the open menu bar present on the top right corner of the browser defined with three vertical dots. Click on the bar and the choose more tools option after that choose the developer tool option from there. After that, the Developer Console will open which will look somewhat like that.

How does the Chrome DevTools console make it easier to develop?

This page explains how the Chrome DevTools Console makes it easier to develop web pages. The Console has 2 main uses: viewing logged messages and running JavaScript. Web developers often log messages to the Console to make sure that their JavaScript is working as expected.

What is the use of a developer console in JavaScript?

It is used to see errors in the code, It is also known as Dev tools embedded in the browsers and provides useful information about a variety of technologies like HTML, DOM, JavaScript, etc. A developer console is a tool which logs the information associated with a web page, such as JavaScript etc.

How to access DevTools console?

DevTools console is a JavaScript interpreter which run any valid JavaScript expression. Let us see how to access the Console in different Web Browsers. In Chrome JavaScript Console is open by navigating to the open menu bar present on the top right corner of the browser defined with three vertical dots.


1 Answers

  • 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.

like image 123
Tiago Fabre Avatar answered Sep 29 '22 07:09

Tiago Fabre