Javascript exception stack trace

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).


Solution 1:

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:

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: