Is there a way to log browser console errors

Suppose a specific user is using Chrome and receives a runtime error that is logged in the Chrome Console. I would like to know what this error is. Currently I need to reach out to a specific user, get them to open the console and tell me what the error is (or send a screenshot).

Is there a way to automatically catch or log this error (no matter what the error is) and send it to the server?

As a follow up question, is there a way to do this for all major browsers?

+3


source to share


1 answer


You can wrap console.log and console.error with logging method



var log = console.log;

console.log = function() {
    //Ajax post arguments to your server for logging
    return log.apply(console, arguments);
};

var error = console.error;

console.error = function() {
    //log arguments to server
    return error.apply(console, arguments); 
};

      

+4


source







All Articles