Gathering detailed insights and metrics for stacktrace-js
Gathering detailed insights and metrics for stacktrace-js
Gathering detailed insights and metrics for stacktrace-js
Gathering detailed insights and metrics for stacktrace-js
Generate, parse, and enhance JavaScript stack traces in all web browsers
npm install stacktrace-js
95.3
Supply Chain
98.2
Quality
80.9
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
3,981 Stars
476 Commits
281 Forks
84 Watching
4 Branches
25 Contributors
Updated on 28 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-21.1%
438,852
Compared to previous day
Last week
-4.8%
2,758,335
Compared to previous week
Last month
4.3%
11,979,387
Compared to previous month
Last year
16%
125,805,780
Compared to previous year
3
31
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.
1var callback = function(stackframes) { 2 var stringifiedStack = stackframes.map(function(sf) { 3 return sf.toString(); 4 }).join('\n'); 5 console.log(stringifiedStack); 6}; 7 8var errback = function(err) { console.log(err.message); }; 9 10StackTrace.get().then(callback).catch(errback); 11//===> Promise(Array[StackFrame], Error) 12//===> callback([ 13// StackFrame({functionName: 'func1', args: [], fileName: 'file.js', lineNumber: 203, columnNumber: 9}), 14// StackFrame({functionName: 'func2', args: [], fileName: 'http://localhost:3000/file.min.js', lineNumber: 1, columnNumber: 3284}) 15//])
HEADS UP: This method does not resolve source maps or guess anonymous function names.
1StackTrace.getSync(); 2//==> [ 3// StackFrame({functionName: 'func1', args: [], fileName: 'file.js', lineNumber: 203, columnNumber: 9}), 4// StackFrame({functionName: 'func2', args: [], fileName: 'http://localhost:3000/file.min.js', lineNumber: 1, columnNumber: 3284}) 5//]
Automatically handle errors
1window.onerror = function(msg, file, line, col, error) { 2 // callback is called with an Array[StackFrame] 3 StackTrace.fromError(error).then(callback).catch(errback); 4};
1var error = new Error('BOOM!'); 2 3StackTrace.fromError(error).then(callback).catch(errback); 4//===> Promise(Array[StackFrame], Error)
This might capture arguments information, but isn't supported in ES5 strict-mode
1StackTrace.generateArtificially().then(callback).catch(errback); 2//===> Promise(Array[StackFrame], Error)
1// callback is called with an Array[StackFrame] every time wrapped function is called 2var myFunc = function(arg) { return 'Hello ' + arg; }; 3var myWrappedFunc = StackTrace.instrument(myFunc, callback, errback); 4//===> Instrumented Function 5myWrappedFunc('world'); 6//===> 'Hello world' 7 8// Use this if you overwrote you original function 9myFunc = StackTrace.deinstrument(myFunc); 10//===> De-instrumented Function
npm install stacktrace-js
bower install stacktrace-js
component install stacktracejs/stacktrace.js
http://cdnjs.com/libraries/stacktrace.js
StackTrace.get(/*optional*/ options)
=> Promise(Array[StackFrame])Generate a backtrace from invocation point, then parse and enhance it.
(Optional) options: Object
filter
returns true
true
to prevent all network requestsStackTrace.getSync(/*optional*/ options)
=> Array[StackFrame]Generate a backtrace from invocation point, then parse it. This method does not use source maps or guess anonymous functions.
(Optional) options: Object
filter
returns true
StackTrace.fromError(error, /*optional*/ options)
=> Promise(Array[StackFrame])Given an Error object, use error-stack-parser to parse it and enhance location information with stacktrace-gps.
error: Error
(Optional) options: Object
filter
returns true
true
to prevent all network requestsStackTrace.generateArtificially(/*optional*/ options)
=> Promise(Array[StackFrame])Use stack-generator to generate a backtrace by walking the arguments.callee.caller
chain.
(Optional) options: Object
filter
returns true
true
to prevent all network requestsStackTrace.instrument(fn, callback, /*optional*/ errback)
=> FunctionGiven 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)
=> FunctionGiven a function that has been instrumented, revert the function to it's original (non-instrumented) state.
StackTrace.report(stackframes, url, message, requestOptions)
=> Promise(String)Given an an error message and Array of StackFrames, serialize and POST to given URL. Promise is resolved with response text from POST request.
Example JSON POST data:
{
message: 'BOOM',
stack: [
{functionName: 'fn', fileName: 'file.js', lineNumber: 32, columnNumber: 1},
{functionName: 'fn2', fileName: 'file.js', lineNumber: 543, columnNumber: 32},
{functionName: 'fn3', fileName: 'file.js', lineNumber: 8, columnNumber: 1}
]
}
headers: {key: val}
is supported.HEADS UP: You won't get the benefit of source maps in IE9- or other very old browsers.
I recommend the stack-trace node package specifically built for node. It has a very similar API and also supports source maps.
This project adheres to the Open Code of Conduct. By participating, you are expected to honor this code.
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:
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/26 approved changesets -- score normalized to 1
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
84 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More