Skip to content

fix(core,browser): Handle errors from other realms - #22926

Open
davidmurdoch wants to merge 2 commits into
getsentry:developfrom
davidmurdoch:david/fix-cross-realm-error-detection
Open

fix(core,browser): Handle errors from other realms#22926
davidmurdoch wants to merge 2 commits into
getsentry:developfrom
davidmurdoch:david/fix-cross-realm-error-detection

Conversation

@davidmurdoch

@davidmurdoch davidmurdoch commented Jul 31, 2026

Copy link
Copy Markdown

Some event-processing paths failed to recognize errors created in another JavaScript realm. This preserves linked causes and AggregateError children, recognizes error-valued object properties, and applies fetch TypeError hostname enhancement across realm boundaries.

Root cause

instanceof Error, instanceof TypeError, and equivalent constructor-based checks depend on prototype identity. Errors from iframes, workers, or other realms have different intrinsic constructors even though they are genuine errors.

These paths now use the SDK’s existing realm-tolerant isError helper. The fetch path additionally checks error.name === "TypeError" to preserve its existing type restriction.

Regression coverage creates errors in a separate Node VM context and exercises both core and browser event builders, aggregate and linked errors, and fetch instrumentation.

Fixes #22925

Replace realm-sensitive Error constructor checks with the existing isError helper. Preserve the fetch TypeError restriction by checking the error name, and add cross-realm regression coverage.

Co-Authored-By: OpenAI Codex <codex@openai.com>
@davidmurdoch
davidmurdoch marked this pull request as ready for review July 31, 2026 20:58
@davidmurdoch
davidmurdoch requested a review from a team as a code owner July 31, 2026 20:58
@davidmurdoch
davidmurdoch requested review from logaretm and msonnb and removed request for a team July 31, 2026 20:58
@Lms24
Lms24 self-requested a review August 3, 2026 14:34
@Lms24 Lms24 self-assigned this Aug 3, 2026

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@davidmurdoch thanks for opening this PR! The fix sounds reasonable to me! One request: could you add a browser integration test that demonstrates the real-life use case? I believe this should happen with an iframe throwing an error with a cause but if you had a different use case that triggered this PR please feel free to use this as a blueprint for the test.

The failing size-limit check is not an issue from your PR. If you rebase it to latest develop it should be gone.

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.

Cross-realm Error objects are not recognized in event processing

2 participants