You can't. What's in the console can't be read from JavaScript.
What you can do is hook the console.log
function so that you store when it logs :
console.stdlog = console.log.bind(console);
console.logs = [];
console.log = function(){
console.logs.push(Array.from(arguments));
console.stdlog.apply(console, arguments);
}
console.logs
contains all what was logged. You can clean it at any time by doing console.logs.length = 0;
.
You can still do a standard, non storing, log by calling console.stdlog
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…