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
- Firefox 0.9+
- Google Chrome 1+
- Safari 3.0+
- Opera 7+
- IE 5.5+
- Konqueror 3.5+
- Flock 1.0+
- SeaMonkey 1.0+
- K-Meleon 1.5.3+
- Epiphany 2.28.0+
- IceApe 1.1+
Get the code!
git clone git://github.com/eriwen/javascript-stacktrace
