Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nextjs integration breaks module load completely in Web Worker, with "document is not defined" #3934

Closed
4 of 9 tasks
gthb opened this issue Aug 30, 2021 · 2 comments
Closed
4 of 9 tasks
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug

Comments

@gthb
Copy link
Contributor

gthb commented Aug 30, 2021

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other: @sentry/next

Version:

6.11.0

Description

Introducing a web worker into my app (which already has a @sentry/next integration), my worker module fails to load, saying document is not defined (because document does not exist in a Web Worker). I get this in the browser console, showing that the failure occurs in Sentry code which accesses document:

getVisibilityWatcher.js?84da:19 Uncaught ReferenceError: document is not defined
    at initHiddenTime (getVisibilityWatcher.js?84da:19)
    at getVisibilityWatcher (getVisibilityWatcher.js?84da:34)
    at getLCP (getLCP.js?00a4:23)
    at MetricsInstrumentation._trackLCP (metrics.js?b67e:235)
    at new MetricsInstrumentation (metrics.js?b67e:20)
    at new BrowserTracing (browsertracing.js?cc79:26)
    at eval (index.client.js?f3e4:25)
    at Module../node_modules/@sentry/nextjs/esm/index.client.js (src_engine_worker_js.js:972)
    at Module.options.factory (src_engine_worker_js.js:2562)
    at __webpack_require__ (src_engine_worker_js.js:2051)

Probably that LCP code (and I'm guessing some more of BrowserTracing) should not be called into at all, when executing in a web worker.

@gthb gthb changed the title Nextjs integration tries to act in Web Worker and borks with "document is not defined" Nextjs integration breaks module load completely in Web Worker, with "document is not defined" Aug 31, 2021
gthb added a commit to gthb/raven-js that referenced this issue Aug 31, 2021
@gthb
Copy link
Contributor Author

gthb commented Aug 31, 2021

Seems like this hinges on MetricsInstrumentation neglecting to disable itself in a worker:

if (!isNodeEnv() && global?.performance) {
if (global.performance.mark) {
global.performance.mark('sentry-tracing-init');
}
this._trackCLS();
this._trackLCP();
this._trackFID();
}

... in a worker, global will be self, which does have the performance attribute, so this will try to instrument the worker for CLS and LCP and FID, which makes no sense (and fails, because that code reasonably assumes there's a document)

gthb added a commit to gthb/raven-js that referenced this issue Aug 31, 2021
@AbhiPrasad AbhiPrasad added Package: nextjs Issues related to the Sentry Nextjs SDK Status: In Progress Type: Bug labels Aug 31, 2021
@AbhiPrasad
Copy link
Member

Will be included with the next release, thanks for your help with the fix!

@smeubank smeubank added this to the Client Reports milestone Sep 30, 2021
@kamilogorek kamilogorek removed this from the Client Reports milestone Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug
Projects
None yet
Development

No branches or pull requests

4 participants