I am writing a monitoring addon for the website.
Is it possible to get logs and errors from the chrome console by JavaScript?
I tried to override the console log and other functions but it only recorded logs generated by my own code.
I would like to catch logs and errors output by 3rd party lib as well. for example, if I am writing a website using jQuery I would like to collect all logs and errors output by jquery as well.
thanks
How about trying this? You can modify the global console.log
const overridedConsole = (function(originConsole){
return {
log: function(text){
originConsole.log(text);
// maybe save?
},
info: function (text) {
originConsole.info(text);
// maybe save?
},
warn: function (text) {
originConsole.warn(text);
// maybe save?
},
error: function (text) {
originConsole.error(text);
// maybe save?
}
};
}(window.console));
//Then redefine the old console
window.console = overridedConsole;