I tried solution suggested here How to get the console.log content as string in JavaScript
Problem is it's missing the full formatted output : it gives a, b, c instead whereas I'd like to get ["a", "b", "c"] for my case https://jsfiddle.net/eywjn9o8/
var logBackup = console.log;
var logMessages = [];
console.log = function() {
logMessages.push.apply(logMessages, arguments);
logBackup.apply(console, arguments);
};
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
alert(logMessages)
Firefox and Google Chrome now have a built-in JSON object, so you can just say alert(JSON.stringify(logMessages)). This is not part of the Javascript language spec, so you shouldn't rely on the JSON object being present in all browsers, but for debugging purposes it's incredibly useful.