-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Description
With Session Replay enabled, the Replay SDK throws when handling an iframe load event:
TypeError: Cannot read properties of undefined (reading 'prototype')
The error originates in @sentry-internal/replay inside ShadowDomManager.patchAttachShadow / observeAttachShadow. When the iframe load listener runs, the code appears to access element.prototype where element is undefined.
Steps to Reproduce
- Create a React app with
@sentry/reactand enable Replay:Sentry.init({ dsn: '...', integrations: [ Sentry.replayIntegration({ /* options */ }), // ...other integrations ], replaysSessionSampleRate: 0, replaysOnErrorSampleRate: 1.0, });
- Add a route that renders a page containing an iframe (e.g. embedded content, PDF viewer, or any
<iframe src="...">that loads). - Use Microsoft Edge (reproduced on Edge 145.0.0 on Windows 10).
- Navigate to that route (e.g.
/training-plansor any page with an iframe). - When the iframe fires its
loadevent, the Replay SDK’s iframe load handler runs and throws when patching Shadow DOM for the iframe.
Minimal repro (conceptual):
- Page with:
<iframe src="https://example.com" title="test" /> - Replay enabled, replaysOnErrorSampleRate > 0.
- Load the page in Edge and wait for the iframe to load.
Expected Behavior
Replay should handle iframe load events without throwing. Either:
- Skip patching when the element/prototype is not available, or
- Guard the prototype access so undefined elements do not cause a TypeError.
Actual Behavior
TypeError: Cannot read properties of undefined (reading 'prototype')is thrown from Replay’s ShadowDomManager.- The error is reported to Sentry as an application error (with Replay context), causing noise and alerting.
- The application itself continues to work; only Sentry’s instrumentation fails.
Stack Trace (from production)
../../node_modules/@sentry/browser/build/npm/esm/prod/helpers.js:93:17 (sentryWrapped)
return fn.apply(this, wrappedArguments);
../../node_modules/@sentry-internal/replay/build/npm/esm/index.js:677:7 (HTMLIFrameElement.<anonymous>)
listener();
../../node_modules/@sentry-internal/replay/build/npm/esm/index.js:1314:13 (listener)
onIframeLoad(
../../node_modules/@sentry-internal/replay/build/npm/esm/index.js:2055:35 (sn.onIframeLoad)
this.shadowDomManager.observeAttachShadow(iframe);
../../node_modules/@sentry-internal/replay/build/npm/esm/index.js:3872:10 (ShadowDomManager.observeAttachShadow)
this.patchAttachShadow(
../../node_modules/@sentry-internal/replay/build/npm/esm/index.js:3884:17 (ShadowDomManager.patchAttachShadow)
element.prototype,
Event context: arguments for the listener were [{ currentTarget: "iframe", isTrusted: true, target: "iframe", type: "load" }].
Environment
- SDK:
@sentry/react10.39.0 (reproduced in production; issue may still exist in 10.40.0). - Browser: Microsoft Edge 145.0.0, Windows 10.
- Mechanism:
auto.browser.browserapierrors.addEventListener. - URL: Occurs on routes that contain iframes (e.g.
/training-plans).
Related
- Shadow DOM / web components support in Replay: Investigate support for shadow dom + web components sentry-javascript#7474
- General class of Replay + iframe/Shadow DOM edge cases in the SDK.
Possible Fix (suggestion)
In the Replay code path that runs on iframe load (e.g. observeAttachShadow / patchAttachShadow), ensure the target element (and its prototype) is defined before accessing element.prototype, or wrap the patch in a try/catch and skip/ignore when the element is undefined or not an HTMLElement.
Metadata
Metadata
Assignees
Labels
Projects
Status