Skip to content

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

@gthb

Description

@gthb

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nextjsIssues related to the Sentry Nextjs SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions