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

后端 未结 1 1731
孤独总比滥情好
孤独总比滥情好 2021-01-05 16:53

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?

相关标签:
1条回答
  • 2021-01-05 17:51

    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);
    
    0 讨论(0)
提交回复
热议问题