PHPackages                             intelogie/stacktrace.js - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. intelogie/stacktrace.js

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

intelogie/stacktrace.js
=======================

0133

Since Dec 9Compare

[ Source](https://github.com/INTELOGIE/stacktrace.js)[ Packagist](https://packagist.org/packages/intelogie/stacktrace.js)[ RSS](/packages/intelogie-stacktracejs/feed)WikiDiscussions Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

stacktrace.js
=============

[](#stacktracejs)

Generate, parse and enhance JavaScript stack traces in all browsers

[![Build Status](https://camo.githubusercontent.com/3b3e38ac43a08d0ef9f667b4d2dcb47dd0282b78288d26a752812dd980ade2a1/68747470733a2f2f7472617669732d63692e6f72672f737461636b74726163656a732f737461636b74726163652e6a732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/stacktracejs/stacktrace.js) [![Coverage Status](https://camo.githubusercontent.com/820bb5dc17a34df7197b368b344262dad4fcf20a3697193a0b43bd42acaca899/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f737461636b74726163656a732f737461636b74726163652e6a732e737667)](https://coveralls.io/r/stacktracejs/stacktrace.js?branch=master) [![GitHub license](https://camo.githubusercontent.com/bde9cab48beba7a293148187671cbb47edbf0b113430099740120646af5ecf84/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f737461636b74726163656a732f737461636b74726163652e6a732e737667)](http://unlicense.org)

Debug and profile your JavaScript with a [stack trace](http://en.wikipedia.org/wiki/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](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) and uses [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)to return an Array of [StackFrames](https://github.com/stacktracejs/stackframe).

#### Upgrading? Check the [0.x -&gt; 1.x Migration Guide](https://www.stacktracejs.com/#!/docs/v0-migration-guide)

[](#upgrading-check-the-0x---1x-migration-guide)

Usage
-----

[](#usage)

#### Get a stack trace from current location

[](#get-a-stack-trace-from-current-location)

```
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).catch(errback)
=> Promise(Array[StackFrame], Error)
=> callback([StackFrame('func1', [], 'file.js', 203, 9), StackFrame('func2', [], 'http://localhost:3000/file.min.js', 1, 3284)])
```

#### window.onerror integration

[](#windowonerror-integration)

Automatically handle errors

```
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

[](#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

[](#generate-a-stacktrace-from-walking-argumentscallee)

This might capture arguments information, but isn't supported in ES5 strict-mode

```
StackTrace.generateArtificially().then(callback).catch(errback)
=> Promise(Array[StackFrame], Error)
```

#### Trace every time a given function is invoked

[](#trace-every-time-a-given-function-is-invoked)

```
// callback is called with an Array[StackFrame] every time wrapped function is called
var myFunc = function(arg) { return 'Hello ' + arg; }
var myWrappedFunc = StackTrace.instrument(myFunc, callback, errback)
=> Instrumented Function
myWrappedFunc('world');
=> 'Hello world'

// Use this if you overwrote you original function
myFunc = StackTrace.deinstrument(myFunc)
=> De-instrumented Function
```

Get stacktrace.js
-----------------

[](#get-stacktracejs)

```
npm install stacktrace-js
bower install stacktrace-js
component install stacktracejs/stacktrace.js
http://cdnjs.com/libraries/stacktrace.js

```

API
---

[](#api)

#### `StackTrace.get(/*optional*/ options)` =&gt; [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)(Array\[[StackFrame](https://github.com/stacktracejs/stackframe)\])

[](#stacktracegetoptional-options--promisearraystackframe)

Generate a backtrace from invocation point, then parse and enhance it.

**(Optional) options: Object**

- *filter: Function([StackFrame](https://github.com/stacktracejs/stackframe) =&gt; Boolean)* - Only include stack entries matching for which `filter` returns `true`
- *sourceCache: Object (String URL =&gt; 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)` =&gt; Array\[[StackFrame](https://github.com/stacktracejs/stackframe)\]

[](#stacktracegetsyncoptional-options--arraystackframe)

Generate a backtrace from invocation point, then parse it. **HEADS UP:** This method does not use source maps or guess anonymous functions.

**(Optional) options: Object**

- *filter: Function([StackFrame](https://github.com/stacktracejs/stackframe) =&gt; Boolean)* - Only include stack entries matching for which `filter` returns `true`

#### `StackTrace.fromError(error, /*optional*/ options)` =&gt; [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)(Array\[[StackFrame](https://github.com/stacktracejs/stackframe)\])

[](#stacktracefromerrorerror-optional-options--promisearraystackframe)

Given an Error object, use [error-stack-parser](https://github.com/stacktracejs/error-stack-parser)to parse it and enhance location information with [stacktrace-gps](https://github.com/stacktracejs/stacktrace-gps).

**error: Error**

**(Optional) options: Object**

- *filter: Function([StackFrame](https://github.com/stacktracejs/stackframe) =&gt; Boolean)* - Only include stack entries matching for which `filter` returns `true`
- *sourceCache: Object (String URL =&gt; 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)` =&gt; [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)(Array\[[StackFrame](https://github.com/stacktracejs/stackframe)\])

[](#stacktracegenerateartificiallyoptional-options--promisearraystackframe)

Use [stack-generator](https://github.com/stacktracejs/stack-generator) to generate a backtrace by walking the `arguments.callee.caller` chain.

**(Optional) options: Object**

- *filter: Function([StackFrame](https://github.com/stacktracejs/stackframe) =&gt; Boolean)* - Only include stack entries matching for which `filter` returns `true`
- *sourceCache: Object (String URL =&gt; 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)` =&gt; Function

[](#stacktraceinstrumentfn-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)` =&gt; Function

[](#stacktracedeinstrumentfn--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)` =&gt; [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)(String)

[](#stacktracereportstackframes-url-message--promisestring)

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}
  ]
}

```

- **message: String** - The error message
- **stackframes: Array([StackFrame](https://github.com/stacktracejs/stackframe))** - Previously wrapped Function
- **url: String** - URL to POST stack JSON to

Browser Support
---------------

[](#browser-support)

[![Sauce Test Status](https://camo.githubusercontent.com/92896dd872bec3e2d1de44f4e08971343398c6a67b353e44d7718c5961503932/68747470733a2f2f73617563656c6162732e636f6d2f62726f777365722d6d61747269782f737461636b74726163656a732e737667)](https://saucelabs.com/u/stacktracejs)

> **HEADS UP**: You won't get the benefit of [source maps](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/)in IE9- or other very old browsers.

Using node.js/io.js only?
-------------------------

[](#using-nodejsiojs-only)

I recommend the [stack-trace node package](https://www.npmjs.com/package/stack-trace) specifically built for node. It has a very similar API and also supports source maps.

Contributing
------------

[](#contributing)

This project adheres to the [Open Code of Conduct](http://todogroup.org/opencodeofconduct/#stacktrace.js/me@eriwen.com). By participating, you are expected to honor this code.

Want to be listed as a *Contributor*? Start with the [Contributing Guide](https://github.com/stacktracejs/stacktrace.js/blob/master/.github/CONTRIBUTING.md)!

This project is made possible due to the efforts of these fine people:

- [Eric Wendelin](https://www.eriwen.com)
- [Victor Homyakov](https://github.com/victor-homyakov)
- [Oliver Salzburg](https://github.com/oliversalzburg)
- [Many others](https://github.com/stacktracejs/stacktrace.js/graphs/contributors)

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 74.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8cd960536c07e255b2e6f7e55c03c6d09274b215ccceaccc38926ffe03e098a7?d=identicon)[bgauthier](/maintainers/bgauthier)

---

Top Contributors

[![eriwen](https://avatars.githubusercontent.com/u/51534?v=4)](https://github.com/eriwen "eriwen (223 commits)")[![victor-homyakov](https://avatars.githubusercontent.com/u/121449?v=4)](https://github.com/victor-homyakov "victor-homyakov (31 commits)")[![oliversalzburg](https://avatars.githubusercontent.com/u/1658949?v=4)](https://github.com/oliversalzburg "oliversalzburg (15 commits)")[![asuth](https://avatars.githubusercontent.com/u/46909?v=4)](https://github.com/asuth "asuth (6 commits)")[![oyvindkinsey](https://avatars.githubusercontent.com/u/108034?v=4)](https://github.com/oyvindkinsey "oyvindkinsey (5 commits)")[![yaroslavya](https://avatars.githubusercontent.com/u/379403?v=4)](https://github.com/yaroslavya "yaroslavya (3 commits)")[![Miroff](https://avatars.githubusercontent.com/u/237006?v=4)](https://github.com/Miroff "Miroff (2 commits)")[![scheib](https://avatars.githubusercontent.com/u/386971?v=4)](https://github.com/scheib "scheib (2 commits)")[![jesstelford](https://avatars.githubusercontent.com/u/612020?v=4)](https://github.com/jesstelford "jesstelford (1 commits)")[![fresheneesz](https://avatars.githubusercontent.com/u/149531?v=4)](https://github.com/fresheneesz "fresheneesz (1 commits)")[![camshaft](https://avatars.githubusercontent.com/u/799311?v=4)](https://github.com/camshaft "camshaft (1 commits)")[![PeterDaveHello](https://avatars.githubusercontent.com/u/3691490?v=4)](https://github.com/PeterDaveHello "PeterDaveHello (1 commits)")[![Raynos](https://avatars.githubusercontent.com/u/479538?v=4)](https://github.com/Raynos "Raynos (1 commits)")[![tomkurt](https://avatars.githubusercontent.com/u/56425?v=4)](https://github.com/tomkurt "tomkurt (1 commits)")[![bgauthier](https://avatars.githubusercontent.com/u/1789355?v=4)](https://github.com/bgauthier "bgauthier (1 commits)")[![xeronimus](https://avatars.githubusercontent.com/u/1777143?v=4)](https://github.com/xeronimus "xeronimus (1 commits)")[![hennr](https://avatars.githubusercontent.com/u/677418?v=4)](https://github.com/hennr "hennr (1 commits)")[![benjamingr](https://avatars.githubusercontent.com/u/1315533?v=4)](https://github.com/benjamingr "benjamingr (1 commits)")[![hlascelles](https://avatars.githubusercontent.com/u/299102?v=4)](https://github.com/hlascelles "hlascelles (1 commits)")

### Embed Badge

![Health badge](/badges/intelogie-stacktracejs/health.svg)

```
[![Health](https://phpackages.com/badges/intelogie-stacktracejs/health.svg)](https://phpackages.com/packages/intelogie-stacktracejs)
```

###  Alternatives

[fjogeleit/prometheus-messenger-middleware

Prometheus Middleware for the Symfony Messenger Component

2255.2k](/packages/fjogeleit-prometheus-messenger-middleware)[spatie/craft-ray

Easily debug CraftCMS projects

1638.4k](/packages/spatie-craft-ray)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
