最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there any way to log browser console errors - Stack Overflow

programmeradmin0浏览0评论

Suppose a particular user is using Chrome, and gets a runtime error which is logged in Chrome's Console. I'd like to know what that error is. Currently I would have to reach out to the specific user, get them to open up the console and tell me what the error is (or send a screenshot).

Is there a way for me to automatically catch or log that error (regardless of 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?

Suppose a particular user is using Chrome, and gets a runtime error which is logged in Chrome's Console. I'd like to know what that error is. Currently I would have to reach out to the specific user, get them to open up the console and tell me what the error is (or send a screenshot).

Is there a way for me to automatically catch or log that error (regardless of 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?

Share Improve this question asked Sep 30, 2014 at 11:52 Allen SAllen S 3,5494 gold badges39 silver badges48 bronze badges 2
  • There are various tools/libraries that do this. Have a look at Sentry for one example. – James Allardice Commented Sep 30, 2014 at 11:56
  • Possible duplicate of Catch all JavaScript errors and send them to server – Martin Omander Commented Sep 10, 2018 at 17:56
Add a ment  | 

1 Answer 1

Reset to default 5

You could wrap console.log and console.error with your 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); 
};
发布评论

评论列表(0)

  1. 暂无评论