Javascript exception stack trace

JavascriptException

Javascript Problem Overview


In Firefox I can get the stack trace of an exception by using exception.stack.

Is there a way to get that in other browsers, too?

Edit: I actually want to save the stack trace automatically (if possible) and not debug it at the time (i.e. I know how to get the stack trace in a debugger).

Javascript Solutions


Solution 1 - Javascript

Place this line where you want to print the stack trace:

console.log(new Error().stack);

Note: tested by me on Chrome 24 and Firefox 18

May be worth taking a look at this tool as well.

Solution 2 - Javascript

Webkit now has functionality that provides stack traces:

Web Inspector: Understanding Stack Traces, posted by Yury Semikhatsky on Wednesday, April 20th, 2011 at 7:32 am (webkit.org)

From that post:

https://www.webkit.org/blog-files/inspector/stack-traces-img/4.png"/>

Solution 3 - Javascript

If you want the string stack trace, I'd go with insin's answer: stacktrace.js. If you want to access the pieces of a stacktrace (line numbers, file names, etc) stackinfo, which actually uses stacktrace.js under the hood.

Solution 4 - Javascript

You must try good open source library TraceKit which attempts to create stack traces for unhandled JavaScript exceptions in all major browsers. You can read more about Tracekit

https://github.com/csnover/TraceKit/

PS: If you are looking for a service(using Tracekit) with good UI, you can try Atatus.

[Disclosure] I work at Atatus.

Solution 5 - Javascript

Not really, at least not easily.

In IE, you can debug the browser process with MS Script Debugger (which for some reason is an Office component) or Visual Studio, and then you can see the stack on breakpoints.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionujhView Question on Stackoverflow
Solution 1 - JavascriptFrancesco CasulaView Answer on Stackoverflow
Solution 2 - JavascriptBrian M. HuntView Answer on Stackoverflow
Solution 3 - JavascriptB TView Answer on Stackoverflow
Solution 4 - JavascriptFizer KhanView Answer on Stackoverflow
Solution 5 - JavascriptlevikView Answer on Stackoverflow