Skip to content

Commit f812877

Browse files
author
rhart
committed
Update docs
1 parent 1be9e92 commit f812877

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Generate, parse and enhance JavaScript stack traces in all browsers
55

66
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).
77

8-
stacktrace.js uses browsers' `Error.stack` mechanism to generate stack traces, parses them, enhances them with
9-
[source maps](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) and uses
8+
stacktrace.js uses browsers' `Error.stack` mechanism to generate stack traces, parses them, enhances them with
9+
[source maps](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) and uses
1010
[Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
1111
to return an Array of [StackFrames](https://github.com/stacktracejs/stackframe).
1212

@@ -16,10 +16,10 @@ to return an Array of [StackFrames](https://github.com/stacktracejs/stackframe).
1616
#### Get a stack trace from current location
1717
```js
1818
var callback = function(stackframes) {
19-
var stringifiedStack = stackframes.map(function(sf) {
20-
return sf.toString();
21-
}).join('\n');
22-
console.log(stringifiedStack);
19+
var stringifiedStack = stackframes.map(function(sf) {
20+
return sf.toString();
21+
}).join('\n');
22+
console.log(stringifiedStack);
2323
};
2424

2525
var errback = function(err) { console.log(err.message); };
@@ -40,7 +40,7 @@ window.onerror = function(msg, file, line, col, error) {
4040

4141
#### Get stack trace from an Error
4242
```js
43-
var error = new Error('BOOM!');
43+
var error = new Error('BOOM!');
4444

4545
StackTrace.fromError(error).then(callback).catch(errback)
4646
=> Promise(Array[StackFrame], Error)
@@ -81,48 +81,49 @@ http://cdnjs.com/libraries/stacktrace.js
8181
Generate a backtrace from invocation point, then parse and enhance it.
8282

8383
**(Optional) options: Object**
84-
* *filter: Function([StackFrame](https://github.com/stacktracejs/stackframe) => Boolean)* - Only include stack entries matching for which `filter` returns `true`
84+
* *filter: Function([StackFrame](https://github.com/stacktracejs/stackframe) => Boolean)* - Only include stack entries matching for which `filter` returns `true`
8585
* *sourceCache: Object (String URL => String Source)* - Pre-populate source cache to avoid network requests
8686
* *offline: Boolean (default: false)* - Set to `true` to prevent all network requests
87-
87+
8888
#### `StackTrace.fromError(error, /*optional*/ options)` => [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)(Array[[StackFrame](https://github.com/stacktracejs/stackframe)])
8989
Given an Error object, use [error-stack-parser](https://github.com/stacktracejs/error-stack-parser)
9090
to parse it and enhance location information with [stacktrace-gps](https://github.com/stacktracejs/stacktrace-gps).
91-
91+
9292
**error: Error**
9393

9494
**(Optional) options: Object**
9595
* *filter: Function([StackFrame](https://github.com/stacktracejs/stackframe) => Boolean)* - Only include stack entries matching for which `filter` returns `true`
9696
* *sourceCache: Object (String URL => String Source)* - Pre-populate source cache to avoid network requests
9797
* *offline: Boolean (default: false)* - Set to `true` to prevent all network requests
98-
98+
9999
#### `StackTrace.generateArtificially(/*optional*/ options)` => [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)(Array[[StackFrame](https://github.com/stacktracejs/stackframe)])
100100
Use [stack-generator](https://github.com/stacktracejs/stack-generator) to generate a backtrace by walking the `arguments.callee.caller` chain.
101101

102102
**(Optional) options: Object**
103103
* *filter: Function([StackFrame](https://github.com/stacktracejs/stackframe) => Boolean)* - Only include stack entries matching for which `filter` returns `true`
104104
* *sourceCache: Object (String URL => String Source)* - Pre-populate source cache to avoid network requests
105105
* *offline: Boolean (default: false)* - Set to `true` to prevent all network requests
106-
106+
107107
#### `StackTrace.instrument(fn, callback, /*optional*/ errback)` => Function
108108
* Given a function, wrap it such that invocations trigger a callback that is called with a stack trace.
109109

110110
* **fn: Function** - to wrap, call callback on invocation and call-through
111111
* **callback: Function** - to call with stack trace (generated by `StackTrace.get()`) when fn is called
112-
* **(Optional) errback: Function** - to call with Error object if there was a problem getting a stack trace.
112+
* **(Optional) errback: Function** - to call with Error object if there was a problem getting a stack trace.
113113
Fails silently (though `fn` is still called) if a stack trace couldn't be generated.
114-
114+
115115
#### `StackTrace.deinstrument(fn)` => Function
116116
Given a function that has been instrumented, revert the function to it's original (non-instrumented) state.
117117

118118
* **fn: Function** - Instrumented Function
119119

120-
#### `StackTrace.report(stackframes, url)` => [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)(String)
121-
Given an Array of StackFrames, serialize and POST to given URL. Promise is resolved with response text from POST request.
120+
#### `StackTrace.report(message, stackframes, url)` => [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)(String)
121+
Given an an error message and Array of StackFrames, serialize and POST to given URL. Promise is resolved with response text from POST request.
122122

123123
Example JSON POST data:
124124
```
125125
{
126+
message: 'BOOM',
126127
stack: [
127128
{functionName: 'fn', fileName: 'file.js', lineNumber: 32, columnNumber: 1},
128129
{functionName: 'fn2', fileName: 'file.js', lineNumber: 543, columnNumber: 32},
@@ -131,6 +132,7 @@ Example JSON POST data:
131132
}
132133
```
133134

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

@@ -140,8 +142,8 @@ Example JSON POST data:
140142
> **HEADS UP**: You won't get the benefit of [source maps](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/)
141143
in IE9- or other very old browsers.
142144

143-
## Using node.js/io.js only?
144-
I recommend the [stack-trace node package](https://www.npmjs.com/package/stack-trace) specifically built for node.
145+
## Using node.js/io.js only?
146+
I recommend the [stack-trace node package](https://www.npmjs.com/package/stack-trace) specifically built for node.
145147
It has a very similar API and also supports source maps.
146148

147149
## Contributing

0 commit comments

Comments
 (0)