admin管理员组

文章数量:1334342

My web page is catching errors with window.onerror and than sends the error to the server for logging. This is working well. However, I stopped seeing the errors on Chrome and Firefox console logs. This makes debugging the application more difficult. Is there any way I can keep using window.onerror yet see the error logs on the console without writing it myself on the onerror? When Chrome is writing the error to the console (if onerror is not used) the stacktrace and navigation to the error source are really helpful.

My web page is catching errors with window.onerror and than sends the error to the server for logging. This is working well. However, I stopped seeing the errors on Chrome and Firefox console logs. This makes debugging the application more difficult. Is there any way I can keep using window.onerror yet see the error logs on the console without writing it myself on the onerror? When Chrome is writing the error to the console (if onerror is not used) the stacktrace and navigation to the error source are really helpful.

Share Improve this question edited Apr 1, 2023 at 19:43 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jan 12, 2014 at 9:13 YosefYosef 3705 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

You have to return false at the end of the error handler to let the default error handler (which logs to the console) run.

window.onerror = function myErrorHandler(errorMsg, url, lineNumber) {
  //Do some of your ajax requests or whatever  

  return false;
}

Out of MDN:

When the function returns true, this prevents the firing of the default event handler.

https://developer.mozilla/en-US/docs/Web/API/GlobalEventHandlers.onerror

本文标签: javascriptCatch errors with windowonerror yet see errors on consoleStack Overflow