diff options
Diffstat (limited to 'js/vendor/tracekit.js')
-rw-r--r-- | js/vendor/tracekit.js | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/js/vendor/tracekit.js b/js/vendor/tracekit.js index 0b06b68493..75491ecabe 100644 --- a/js/vendor/tracekit.js +++ b/js/vendor/tracekit.js @@ -128,6 +128,7 @@ TraceKit.report = (function reportModuleWrapper() { */ function subscribe(handler) { installGlobalHandler(); + installGlobalUnhandledRejectionHandler(); handlers.push(handler); } @@ -144,8 +145,8 @@ TraceKit.report = (function reportModuleWrapper() { } if (handlers.length === 0) { - window.onerror = _oldOnerrorHandler; - _onErrorHandlerInstalled = false; + uninstallGlobalHandler(); + uninstallGlobalUnhandledRejectionHandler(); } } @@ -178,6 +179,7 @@ TraceKit.report = (function reportModuleWrapper() { } var _oldOnerrorHandler, _onErrorHandlerInstalled; + var _oldOnunhandledrejectionHandler, _onUnhandledRejectionHandlerInstalled; /** * Ensures all global unhandled exceptions are recorded. @@ -235,6 +237,18 @@ TraceKit.report = (function reportModuleWrapper() { } /** + * Ensures all unhandled rejections are recorded. + * @param {PromiseRejectionEvent} e event. + * @memberof TraceKit.report + * @see https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onunhandledrejection + * @see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent + */ + function traceKitWindowOnUnhandledRejection(e) { + var stack = TraceKit.computeStackTrace(e.reason); + notifyHandlers(stack, true, e.reason); + } + + /** * Install a global onerror handler * @memberof TraceKit.report */ @@ -249,6 +263,42 @@ TraceKit.report = (function reportModuleWrapper() { } /** + * Uninstall the global onerror handler + * @memberof TraceKit.report + */ + function uninstallGlobalHandler() { + if (_onErrorHandlerInstalled) { + window.onerror = _oldOnerrorHandler; + _onErrorHandlerInstalled = false; + } + } + + /** + * Install a global onunhandledrejection handler + * @memberof TraceKit.report + */ + function installGlobalUnhandledRejectionHandler() { + if (_onUnhandledRejectionHandlerInstalled === true) { + return; + } + + _oldOnunhandledrejectionHandler = window.onunhandledrejection; + window.onunhandledrejection = traceKitWindowOnUnhandledRejection; + _onUnhandledRejectionHandlerInstalled = true; + } + + /** + * Uninstall the global onunhandledrejection handler + * @memberof TraceKit.report + */ + function uninstallGlobalUnhandledRejectionHandler() { + if (_onUnhandledRejectionHandlerInstalled) { + window.onunhandledrejection = _oldOnunhandledrejectionHandler; + _onUnhandledRejectionHandlerInstalled = false; + } + } + + /** * Process the most recent exception * @memberof TraceKit.report */ |