How to hook into console error and warnings posted by browser. due to internal browser errors. I mean how can I hook into error likes security violation logs
******* ...... it violates the following Content Security Policy directive: "frame-src 'self' *.wholefoodsmarket.com https://*.google.com *.acquia-sites.com".
So I want to get all the error messages present in the console in a single var.
I tried to override the default console functions but not still cannot hook into these types of logs.
My code now
var consoleLogFn = console.log;
var consoleWarnFn = console.warn;
var consoleErrorFn = console.error;
window.jsErrors = window.jsErrors || [];
console.log = function(){
consoleLogFn.apply(console, arguments);
var args = Array.prototype.slice.call(arguments);
for(var i=0;i<args.length;i++){
pushLog('log', args[i]);
}
}
console.warn = function(){
consoleWarnFn.apply(console, arguments);
var args = Array.prototype.slice.call(arguments);
for(var i=0;i<args.length;i++){
pushLog('warn', args[i]);
}
}
console.error = function(){
consoleErrorFn.apply(console, arguments);
var args = Array.prototype.slice.call(arguments);
for(var i=0;i<args.length;i++){
pushLog('error', args[i]);
}
}
console.debug = function(){
consoleErrorFn.apply(console, arguments);
var args = Array.prototype.slice.call(arguments);
for(var i=0;i<args.length;i++){
pushLog('debug', args[i]);
}
}
var pushLog = function(type, msg){
window.jsErrors.push({
'type': type,
'message': msg,
});
}