Skip to content

Incorrect TypeScript typings for Sentry.registerWebWorker() #17444

Closed

Description

@medmunds

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/browser

SDK Version

10.5.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

Sentry.registerWebWorker() is intended to be called from within a worker's implementation. But its TypeScript typings expect a Worker instance, which is only available in the thread that created new Worker(). The type of self within the worker instance will be an extension of WorkerGlobalScope (DedicatedWorkerGlobalScope or ServiceWorkerGlobalScope or SharedWorkerGlobalScope), not Worker.

Suggested fix in webWorker.ts:

  interface RegisterWebWorkerOptions {
-   self: Worker & { _sentryDebugIds?: Record<string, string> };
+   self: WorkerGlobalScope & { _sentryDebugIds?: Record<string, string> };
  }

Steps to Reproduce

  1. npm install @sentry/browser@10.5.0
  2. Create worker.ts:
    import * as Sentry from "@sentry/browser";
    
    Sentry.registerWebWorker({ self });
  3. Ensure the libs in your tsconfig.json are set up to compile that file as a web worker, e.g.:
    { 
      "compilerOptions": { 
        "lib": ["ES2022", "WebWorker"], 
        "...other": "settings..." 
      },
      "include": ["src/worker.ts"]
    }
  4. Attempt to compile the file

Expected Result

No errors

Actual Result

TS2322: Type 'DedicatedWorkerGlobalScope' is not assignable
to type 'Worker & { _sentryDebugIds?: Record<string, string> | undefined; }'.
Property 'terminate' is missing in type 'DedicatedWorkerGlobalScope' but required in type 'Worker'.

Screenshot:
Image

Workaround:

Sentry.registerWebWorker({ self as unknown as Worker });

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Aug 22, 2025
  2. Lms24 commented on Aug 22, 2025

    @Lms24
    Member

    Thanks, will take a look on Monday

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Aug 22, 2025
  4. self-assigned this
    on Aug 25, 2025
  5. Lms24 commented on Aug 25, 2025

    @Lms24
    Member

    Opened #17447 with the fix. We'll include this in the next release sometime this week. Thanks for reporting!

  6. github-actions commented on Aug 26, 2025

    @github-actions
    Contributor

    A PR closing this issue has just been released 🚀

    This issue was referenced by PR #17447, which was included in the 10.6.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions