Get stacktrace from error event

I am implementing a global exception handler that should log the exception and send information to the server. Right now my code looks like

window.addEventListener('error', function (errorEvent) {
  var errorLine = '';
  if (errorEvent.filename) {
    var lastSlashIndex = errorEvent.filename.lastIndexOf('/');
    errorLine += errorEvent.filename.substr(lastSlashIndex + 1);
  }
  if (errorEvent.lineno) errorLine += ':' + errorEvent.lineno;
  if (errorEvent.message) errorLine += ' ' + errorEvent.message;

      

So, I can extract the location where the exception was thrown, but not the full stack trace. I researched the error event that is passed back to the event listener, but I couldn't find any information on the stack trace. Is it possible to get this information from an event listener callback?

I am interested in Safari mobile and mobile phone solution, but any other information is appreciated of course.

+3


source to share


1 answer


The best you can do is use the stacktrace.js library , but if you want to do it yourself, take a look at this link and this link for V8 . The tricky part is that you will get a different format for different browsers, so you better use a library or study its code.



+2


source







All Articles