When importing @sentry/browser from a service worker file (e.g: background.js) like
import * as Sentry from '@sentry/browser';
we get
Uncaught TypeError: Cannot read properties of undefined (reading 'visibilityState')
var initHiddenTime = () => {
return (0,_sentry_utils__WEBPACK_IMPORTED_MODULE_0__.getGlobalObject)().document.visibilityState === 'hidden' ? 0 : Infinity;
};
It crashes at the import level, because @sentry/browser relies on the document which doesn't exist in the context of a background script.
Edit: That's because I was loading BrowserTracing, when removing it it doesn't crash!
Originally posted by @Vadorequest in #4098 (comment)
When importing
@sentry/browserfrom a service worker file (e.g: background.js) likewe get
It crashes at the import level, because @sentry/browser relies on the
documentwhich doesn't exist in the context of a background script.Edit: That's because I was loading
BrowserTracing, when removing it it doesn't crash!Originally posted by @Vadorequest in #4098 (comment)