diff --git a/README.md b/README.md index 7d5aac0..719e5ac 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/tracekit.js b/tracekit.js index 78bb33b..554b0f4 100644 --- a/tracekit.js +++ b/tracekit.js @@ -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;