Generate, parse, and enhance JavaScript stack traces in all web browsers
Installations
npm install stacktrace-js
Score
95.3
Supply Chain
98.2
Quality
80.9
Maintenance
100
Vulnerability
100
License
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
8.16.0
NPM Version
6.4.1
Statistics
3,981 Stars
476 Commits
281 Forks
84 Watching
4 Branches
25 Contributors
Updated on 28 Nov 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
431,513,544
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Dev Dependencies
31
stacktrace.js
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.
Upgrading? Check the 0.x -> 1.x Migration Guide
Usage
Get a stack trace from current location
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//])
You can also get a stack trace synchronously
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//]
window.onerror integration
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};
Get stack trace from an Error
1var error = new Error('BOOM!'); 2 3StackTrace.fromError(error).then(callback).catch(errback); 4//===> Promise(Array[StackFrame], Error)
Generate a stacktrace from walking arguments.callee
This might capture arguments information, but isn't supported in ES5 strict-mode
1StackTrace.generateArtificially().then(callback).catch(errback); 2//===> Promise(Array[StackFrame], Error)
Trace every time a given function is invoked
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
Get stacktrace.js
npm install stacktrace-js
bower install stacktrace-js
component install stacktracejs/stacktrace.js
http://cdnjs.com/libraries/stacktrace.js
API
StackTrace.get(/*optional*/ options)
=> Promise(Array[StackFrame])
Generate a backtrace from invocation point, then parse and enhance it.
(Optional) options: Object
- filter: Function(StackFrame => Boolean) - Only include stack entries matching for which
filter
returnstrue
- 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
StackTrace.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: Function(StackFrame => Boolean) - Only include stack entries matching for which
filter
returnstrue
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: Function(StackFrame => Boolean) - Only include stack entries matching for which
filter
returnstrue
- 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
StackTrace.generateArtificially(/*optional*/ options)
=> Promise(Array[StackFrame])
Use stack-generator to generate a backtrace by walking the arguments.callee.caller
chain.
(Optional) options: Object
- filter: Function(StackFrame => Boolean) - Only include stack entries matching for which
filter
returnstrue
- 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
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.
- fn: Function - Instrumented Function
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}
]
}
- stackframes: Array(StackFrame) - Previously wrapped Function
- url: String - URL to POST stack JSON to
- message: String - The error message
- requestOptions: Object - HTTP request options object. Only
headers: {key: val}
is supported.
Browser Support
HEADS UP: You won't get the benefit of source maps in IE9- or other very old browsers.
Using node.js/io.js only?
I recommend the stack-trace node package specifically built for node. It has a very similar API and also supports source maps.
Contributing
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
Project has not signed or included provenance with any releases.
Details
- Warn: release artifact v1.3.0 not signed: https://api.github.com/repos/stacktracejs/stacktrace.js/releases/3432574
- Warn: release artifact v1.3.0 does not have provenance: https://api.github.com/repos/stacktracejs/stacktrace.js/releases/3432574
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 7 are checked with a SAST tool
Reason
84 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-pp7h-53gx-mx7r
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-wg6g-ppvx-927h
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-4gxf-g5gf-22h4
- Warn: Project is vulnerable to: GHSA-vh7m-p724-62c2
- Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-j4f2-536g-r55m
- Warn: Project is vulnerable to: GHSA-r7qp-cfhv-p84w
- Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q
- Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-6x33-pw7p-hmpq
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-jg8v-48h5-wgxg
- Warn: Project is vulnerable to: GHSA-36fh-84j7-cv5h
- Warn: Project is vulnerable to: GHSA-7x7c-qm48-pq9c
- Warn: Project is vulnerable to: GHSA-rc3x-jf5g-xvc5
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-82v2-mx6x-wq7q
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-hxm2-r34f-qmc5
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-8hfj-j24r-96c4
- Warn: Project is vulnerable to: GHSA-wc69-rhjr-hc9g
- Warn: Project is vulnerable to: GHSA-56x4-j7p9-fcf9
- Warn: Project is vulnerable to: GHSA-v78c-4p63-2j6c
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-wrh9-cjv3-2hpw
- Warn: Project is vulnerable to: GHSA-8c25-f3mj-v6h8
- Warn: Project is vulnerable to: GHSA-vqfx-gj96-3w95
- Warn: Project is vulnerable to: GHSA-f598-mfpv-gmfx
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-fxwf-4rqh-v8g3
- Warn: Project is vulnerable to: GHSA-25hc-qcg6-38wj
- Warn: Project is vulnerable to: GHSA-xfhh-g9f5-x4m4
- Warn: Project is vulnerable to: GHSA-qm95-pgcg-qqfq
- Warn: Project is vulnerable to: GHSA-cqmj-92xf-r6r9
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-mgfv-m47x-4wqp
- Warn: Project is vulnerable to: GHSA-qgmg-gppg-76g5
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-776f-qx25-q3cc
- Warn: Project is vulnerable to: GHSA-72mh-269x-7mh5
- Warn: Project is vulnerable to: GHSA-h4j5-c7cj-74xg
Score
1.7
/10
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