Store console logging in Chrome in a persistent way

console, google-chrome, javascript, logging, persistent

Solution

Here's a little function that stores logs into the WebStorage (persists across 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'd have 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);
    });
}());

Problem

In a school project I am running some javascript that are inputted through the console window and run from there. This script manipulates the web page and outputs the results to the console. PROBLEM: Keep / save these results in a persistant manner that does not go away on browser close, script malfunctioning / page reload, or if possible, pc crash. I thought of using frameworks such as Log4js or jStorage (jQuery Storage), but as this is not my website I'm manipulating, I can't add code or markup to the page. Is there any way to do this? NOTE: It is not critical that I log the results to console, I could send them off somewhere or do something else with them if that makes it more easy to log. Thanks.

Original source