Get console history

前端 未结 4 764
無奈伤痛
無奈伤痛 2020-12-30 01:42

I\'d like to know if there is a way in javascript to retrieve console history.

What I mean by console history is what appears in the dev tools console. For instance,

4条回答
  •  清歌不尽
    2020-12-30 02:38

    console.history = [];
    var oldConsole = {};
    for (var i in console) {
        if (typeof console[i] == 'function') {
            oldConsole[i] = console[i];
            var strr = '(function(){\
                console.history.push({func:\'' + i + '\',args : Array.prototype.slice.call(arguments)});\
                oldConsole[\'' + i + '\'].apply(console, arguments);\
            })';
            console[i] = eval(strr);
        }
    }
    

    And then use console.history to access history

提交回复
热议问题