Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to read the console.log using Javascript?

The title is pretty self-explanatory..

Is there a way to read whatever's been output to the console.log up until the moment you decide to read it, using Javascript?

like image 804
Sprout Coder Avatar asked Sep 19 '13 21:09

Sprout Coder


1 Answers

You can make a proxy around it, such as :

(function(win){
    var ncon = win.console;

    var con = win.console = {
        backlog: []
    };

    for(var k in ncon) {
        if(typeof ncon[k] === 'function') {
            con[k] = (function(fn) {
                return function() {
                    con.backlog.push([new Date(), fn, arguments]);
                    ncon[fn].apply(ncon, arguments);
                };
            })(k);
        }
    }
})(window);
like image 116
OneOfOne Avatar answered Nov 07 '22 08:11

OneOfOne