Keep console in Chrome permanently

In a school project, I run some javascript, which is entered through the console window and launched from there. This script controls the web page and displays the results to the console.

PROBLEM: Save / save these results in a stable manner that does not disappear when you close the browser, script crashes / reloads the page or, if possible, crashes the PC.

I was thinking about using frameworks like Log4js or jStorage (jQuery Storage), but since this is not my site, I am manipulating, I cannot add code or markup to the page.

Is there any way to do this?

NOTE. It doesn’t matter that I record the results for the console, I could send them somewhere or do something else with them if this makes recording easier.

Thanks.

+6
source share
3 answers

If you want to automatically save everything in the Chrome Console, you need to start Chrome with these options:

--enable-logging --v=1 

It will save the full chrome log in its data directory (note that the file will be overwritten in every run). More details here .

Alternative way: install Sawbuck to manage Chrome logs.

+8
source

Here's a little function that stores logs in WebStorage (stored in browser sessions):

 console.plog = function () { var key = Date.now(); var value = JSON.stringify([].slice.call(arguments)); localStorage.setItem(key, value); console.log.apply(console, arguments); } 

To restore the logs, you need to run the following expression:

 (function restoreLogs() { var timestamps = Object.keys(localStorage).sort(); timestamps.forEach(function (ts) { var logArgs = JSON.parse(localStorage.getItem(ts)); console.log.apply(console, logArgs); }); }()); 
+7
source

Use console.error(arg); - it will send a console message to the stderr browser (I'm sure it will also do this in release builds.)

Launch your browser from the command line and redirect stderr to some file (something along the lines of chrome 2>errlog ).

+1
source

Source: https://habr.com/ru/post/913524/


All Articles