Skip to content

fix(session-replay): prevent blob worker errors from surfacing as uncaught#1561

Open
lewgordon-amplitude wants to merge 2 commits intomainfrom
fix/sr-worker-onerror-prevent-default
Open

fix(session-replay): prevent blob worker errors from surfacing as uncaught#1561
lewgordon-amplitude wants to merge 2 commits intomainfrom
fix/sr-worker-onerror-prevent-default

Conversation

@lewgordon-amplitude
Copy link
Collaborator

@lewgordon-amplitude lewgordon-amplitude commented Feb 27, 2026

Summary

When new Worker(blobUrl) fails (e.g. Firefox ETP, private browsing), the onerror handler correctly falls back to sync compression but was not calling e.preventDefault(). Per the Worker spec this causes the ErrorEvent to re-fire on window.onerror, making a graceful degradation appear as an unhandled crash in the console and error monitoring. This is related to a sentry error we're seeing on Amplitude: https://amplitude.sentry.io/explore/releases/2b6289da0df5804a5c2ae4d63fdfb90d8876744e/?project=78869

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: No

Note

Low Risk
Low risk: a small change to web worker error handling plus a targeted unit test; behavior remains a graceful fallback to non-worker compression.

Overview
Fixes session replay web-worker compression fallback by calling preventDefault() in EventCompressor’s worker.onerror handler, preventing worker errors from bubbling to window.onerror as uncaught.

Adds a unit test to assert preventDefault() is invoked and that the existing fallback behavior still terminates the worker and clears eventCompressor.worker.

Written by Cursor Bugbot for commit a95307d. This will update automatically on new commits. Configure here.

…aught

When new Worker(blobUrl) fails (e.g. Firefox ETP, private browsing),
the onerror handler correctly falls back to sync compression but was
not calling e.preventDefault(). Per the Worker spec this causes the
ErrorEvent to re-fire on window.onerror, making a graceful degradation
appear as an unhandled crash in the console and error monitoring.

Fixes SR-2657

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lewgordon-amplitude
Copy link
Collaborator Author

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@lewgordon-amplitude lewgordon-amplitude marked this pull request as ready for review February 27, 2026 14:22
@lewgordon-amplitude lewgordon-amplitude requested a review from a team as a code owner February 27, 2026 14:22
Adds a test that properly verifies e.preventDefault() is called when
the blob worker fires an error, using a MockWorker with an onerror setter
to capture and invoke the handler with a real mock ErrorEvent.

The existing test.each error case was passing incidentally — the
TypeError from calling preventDefault on a plain object was silently
swallowed by addCompressedEvent's DataCloneError try/catch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant