Skip to content

feat(browser): Add debugId sync APIs between web worker and main thread #16981

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

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Jul 14, 2025

This PR adds two Browser SDK APIs to let the main thread know about debugIds of worker files:

  • webWorkerIntegration(worker) to be used in the main thread
  • registerWebWorker(self) to be used in the web worker

The communication between workers and main thread is established between both APIs and they have to be used both for the sync to work correctly. Another limitation around this approach is that users must set up webWorkerInegration before they register their own message listeners. This ensures that the message from registerWebWorker is not propagated to user-created message listeners. We'll document this thoroughly in docs and I already added a section about this in the JSDoc.

Because of the strict co-dependence of both APIs, I decided to add them in one PR (also makes testing easier).

Usage Example

// main.js
Sentry.init({...})

const worker = new MyWorker(...);

Sentry.addIntegration(Sentry.webWorkerIntegration(worker));

worker.addEventListener('message', e => {...});
// worker.js
Sentry.registerWebWorker(self);

self.postMessage(...);

closes #16975
closes #16976

@Lms24 Lms24 self-assigned this Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add worker thread Sentry.registerWorker(self) API Add main thread webWorkerIntegration
1 participant