A JavaScript tool that allows you to debug your JavaScript by giving you a stack trace of function calls leading to an error (or any condition you specify).
The promises referenced below are ES6-Promises.
var callback = function(stackframes) {
var stringifiedStack = stackframes.map(function(sf) {
return sf.toString();
}).join('\n');
console.log(stringifiedStack);
};
var errback = function(err) { console.log(err.message); };
StackTrace.get().then(callback, errback)
=> Promise(Array[StackFrame](https://github.com/stacktracejs/stackframe), Error)
=> callback([StackFrame('func1', [], 'file.js', 203, 9), StackFrame('func2', [], 'http://localhost:3000/file.min.js', 1, 3284)])
// Somewhere else...
var error = new Error('BOOM!');
StackTrace.fromError(error).then(callback, errback)
=> Promise(Array[StackFrame](https://github.com/stacktracejs/stackframe), Error)
StackTrace.generateArtificially().then(callback, errback)
=> Promise(Array[StackFrame](https://github.com/stacktracejs/stackframe), Error)
StackTrace.instrument(interestingFn, callback, errback)
=> Instrumented Function
StackTrace.deinstrument(interestingFn)
=> De-instrumented Function
npm install stacktrace-js
bower install stacktrace-js
https://rawgithub.com/stacktracejs/stacktrace.js/master/dist/stacktrace.min.js
https://cdnjs.com/libraries/stacktrace.js
//cdnjs.cloudflare.com/ajax/libs/stacktrace.js/0.6.4/stacktrace.min.js
Generate a backtrace from invocation point, then parse and enhance it. options: Object
- sourceCache: Object (String URL => String Source) - Pre-populate source cache to avoid network requests
- offline: Boolean (default: false) - Set to
true
to prevent all network requests
Given an Error object, use error-stack-parser to parse it and enhance location information with stacktrace-gps.
- sourceCache: Object (String URL => String Source) - Pre-populate source cache to avoid network requests
- offline: Boolean (default: false) - Set to
true
to prevent all network requests
Use stack-generator to generate a backtrace by walking the arguments.callee.caller
chain.
- sourceCache: Object (String URL => String Source) - Pre-populate source cache to avoid network requests
- offline: Boolean (default: false) - Set to
true
to prevent all network requests
Call callback with a stack trace anytime fn
is called. Returns true
if given Function is successfully instrumented
- 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 - errback - (Optional) 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.
Remove StackTrace instrumentation on fn
. Returns true
if deinstrumentation succeeds.
- fn - Previously wrapped Function
- Chrome 1+
- Firefox 3+
- Safari 5+
- Opera 9+
- IE 6+
- iOS 7+
- Android 4.0+
NOTE: You won't get the benefit of source maps in IE9- or other very old browsers.
I recommend the stack-trace node package. It has a very similar API and also supports source maps.
Want to be listed as a Contributor? Start with the Contributing Guide!
This project is made possible due to the efforts of these fine people:
This project is licensed to the Public Domain