stacktrace.js

Framework-agnostic, micro-library for getting stack traces in all web browsers
Fork me on GitHub

Usage

Just include stacktrace.js and call printStackTrace()!

<script type="text/javascript" src="path/to/stacktrace.js" />
<script type="text/javascript">
	// ... your code ...
	if (errorCondition) {
		 var trace = printStackTrace();
		 alert(trace.join(' -> ')); //Output however you want!
	}
	// ... more code of yours ...
</script>

Function Instrumentation

Give it a shot by clicking here

var p = new printStackTrace.implementation();
p.instrumentFunction(this, 'baz', logStackTrace);
function logStackTrace(stack) {
	console.log(stack.join(' -> '));
}
function foo() {
	var a = 1;
	bar();
}
function bar() {
	baz();
}
foo(); //Will log a stacktrace when 'baz()' is called containing 'foo()'!
 
p.deinstrumentFunction(this, 'baz'); //Remove function instrumentation

Browser Support

Get the code!

git clone git://github.com/eriwen/javascript-stacktrace