Skip to content
This repository was archived by the owner on Jan 21, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ You can also tell TraceKit to ignore global window errors with:
TraceKit.collectWindowErrors = false;
```

### Existing `window.onerror` function?

TraceKit installs it's own window.onerror function, but yours will still get called normally.
If you don't want TraceKit to notify subscribers, then `return {notifyHandlers: false};` from your window.onerror function.

View the source for more details and examples.

![Stacktrace or GTFO](http://i.imgur.com/jacoj.jpg)
Expand Down
13 changes: 10 additions & 3 deletions tracekit.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,17 @@ TraceKit.report = (function reportModuleWrapper() {
};
}

notifyHandlers(stack, 'from window.onerror');

if (_oldOnerrorHandler) {
return _oldOnerrorHandler.apply(this, arguments);
var _oldOnerrorReturn = _oldOnerrorHandler.apply(this, arguments);

// if there is no return value or that return value has notifyHandlers set to something truthy, notifyHandlers
if (!_oldOnerrorReturn || _oldOnerrorReturn.notifyHandlers) {
notifyHandlers(stack, 'from window.onerror');
}

return _oldOnerrorReturn; // preserve any potential return behavior of the old onerror function.
} else {
notifyHandlers(stack, 'from window.onerror');
}

return false;
Expand Down