Skip to content

Commit

Permalink
Enable uncaught error capture for web workers (#929)
Browse files Browse the repository at this point in the history
* fix: safely check for document and window

* fix: don't treat web worker errors as anonymous in chrome
  • Loading branch information
waltjones authored Mar 3, 2021
1 parent d6fc5f0 commit c478f09
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion sdks/rollbar.js/src/browser/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ Rollbar.prototype.handleUncaughtException = function(message, url, lineno, colno

// Chrome will always send 5+ arguments and error will be valid or null, not undefined.
// If error is undefined, we have a different caller.
if (this.options.inspectAnonymousErrors && this.isChrome && (error === null)) {
// Chrome also sends errors from web workers with null error, but does not invoke
// prepareStackTrace() for these. Test for empty url to skip them.
if (this.options.inspectAnonymousErrors && this.isChrome && error === null && url === '') {
return 'anonymous';
}

Expand Down
4 changes: 2 additions & 2 deletions sdks/rollbar.js/src/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ function makeUnhandledStackInfo(
};
location.func = errorParser.guessFunctionName(location.url, location.line);
location.context = errorParser.gatherContext(location.url, location.line);
var href = document && document.location && document.location.href;
var useragent = window && window.navigator && window.navigator.userAgent;
var href = typeof document !== 'undefined' && document && document.location && document.location.href;
var useragent = typeof window !== 'undefined' && window && window.navigator && window.navigator.userAgent;
return {
'mode': mode,
'message': error ? String(error) : (message || backupMessage),
Expand Down

0 comments on commit c478f09

Please sign in to comment.