Generate, parse and enhance JavaScript stack traces in all browsers
Debug and profile your JavaScript with a stack trace of function calls leading to an error (or any condition you specify).
stacktrace.js uses browsers' Error.stack mechanism to generate stack traces, parses them, enhances them with
source maps and uses
Promises
to return an Array of StackFrames.
window.onerror = function(msg, file, line, col, error) { // callback is called with an Array[StackFrame] StackTrace.fromError(error).then(callback).catch(errback);};
Get stack trace from an Error
var error = new Error('BOOM!');StackTrace.fromError(error).then(callback).catch(errback);//===> Promise(Array[StackFrame], Error)
Generate a stacktrace from walking arguments.callee
This might capture arguments information, but isn't supported in ES5 strict-mode
// callback is called with an Array[StackFrame] every time wrapped function is calledvar myFunc = function(arg) { return 'Hello ' + arg; };var myWrappedFunc = StackTrace.instrument(myFunc, callback, errback);//===> Instrumented FunctionmyWrappedFunc('world');//===> 'Hello world'// Use this if you overwrote you original functionmyFunc = StackTrace.deinstrument(myFunc);//===> De-instrumented Function
offline: Boolean (default: false) - Set to true to prevent all network requests
StackTrace.instrument(fn, callback, /*optional*/ errback) => Function
Given a function, wrap it such that invocations trigger a callback that is called with a stack trace.
fn: Function - to wrap, call callback on invocation and call-through
callback: Function - to call with stack trace (generated by StackTrace.get()) when fn is called
(Optional) errback: Function - to call with Error object if there was a problem getting a stack trace.
Fails silently (though fn is still called) if a stack trace couldn't be generated.
StackTrace.deinstrument(fn) => Function
Given a function that has been instrumented, revert the function to it's original (non-instrumented) state.