有没有办法使用 Javascript 读取 console.log?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18905393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 13:38:32 来源:igfitidea点击:
Is there a way to read the console.log using Javascript?
提问by Sprout Coder
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?
有没有办法使用 Javascript 读取输出到 console.log 的任何内容,直到您决定读取它为止?
采纳答案by OneOfOne
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);