-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
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
npm install @sentry/[email protected]
- Create worker.ts:
import * as Sentry from "@sentry/browser"; Sentry.registerWebWorker({ self });
- 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"] }
- 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'.
Workaround:
Sentry.registerWebWorker({ self as unknown as Worker });
Metadata
Metadata
Assignees
Projects
Status
No status