Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as Sentry from '@sentry/browser';

// type cast necessary because TS thinks this file is part of the main
// thread where self is of type `Window` instead of `Worker`
Sentry.registerWebWorker({ self: self as unknown as Worker });
Sentry.registerWebWorker({ self });

// Let the main thread know the worker is ready
self.postMessage({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as Sentry from '@sentry/browser';

// type cast necessary because TS thinks this file is part of the main
// thread where self is of type `Window` instead of `Worker`
Sentry.registerWebWorker({ self: self as unknown as Worker });
Sentry.registerWebWorker({ self });

// Let the main thread know the worker is ready
self.postMessage({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as Sentry from '@sentry/browser';

// type cast necessary because TS thinks this file is part of the main
// thread where self is of type `Window` instead of `Worker`
Sentry.registerWebWorker({ self: self as unknown as Worker });
Sentry.registerWebWorker({ self });

// Let the main thread know the worker is ready
self.postMessage({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"lib": ["ES2022", "DOM", "DOM.Iterable", "WebWorker"],
"skipLibCheck": false,
"skipDefaultLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
Expand Down
19 changes: 16 additions & 3 deletions packages/browser/src/integrations/webWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface WebWorkerIntegration extends Integration {
* any messages from the worker. Otherwise, your message handlers will receive
* messages from the Sentry SDK which you need to ignore.
*
* This integration only has an effect, if you call `Sentry.registerWorker(self)`
* This integration only has an effect, if you call `Sentry.registerWebWorker(self)`
* from within the worker(s) you're adding to the integration.
*
* Given that you want to initialize the SDK as early as possible, you most likely
Expand Down Expand Up @@ -113,8 +113,21 @@ function listenForSentryDebugIdMessages(worker: Worker): void {
});
}

/**
* Minimal interface for DedicatedWorkerGlobalScope, only requiring the postMessage method.
* (which is the only thing we need from the worker's global object)
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope
*
* We can't use the actual type because it breaks everyone who doesn't have {"lib": ["WebWorker"]}
* but uses {"skipLibCheck": true} in their tsconfig.json.
*/
interface MinimalDedicatedWorkerGlobalScope {
postMessage: (message: unknown) => void;
}

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

/**
Expand All @@ -125,7 +138,7 @@ interface RegisterWebWorkerOptions {
* import * as Sentry from '@sentry/<your-sdk>';
*
* // Do this as early as possible in your worker.
* Sentry.registerWorker({ self });
* Sentry.registerWebWorker({ self });
*
* // continue setting up your worker
* self.postMessage(...)
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"include": ["src/**/*", "test/loader.js"],

"compilerOptions": {
"lib": ["DOM", "ES2018"],
"lib": ["DOM", "ES2018", "WebWorker"]
}
}
Loading