Skip to content

Replay: TypeError (reading 'prototype') when handling iframe load in ShadowDomManager #266

@esetnik

Description

@esetnik

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

  1. Create a React app with @sentry/react and enable Replay:
    Sentry.init({
      dsn: '...',
      integrations: [
        Sentry.replayIntegration({ /* options */ }),
        // ...other integrations
      ],
      replaysSessionSampleRate: 0,
      replaysOnErrorSampleRate: 1.0,
    });
  2. Add a route that renders a page containing an iframe (e.g. embedded content, PDF viewer, or any <iframe src="..."> that loads).
  3. Use Microsoft Edge (reproduced on Edge 145.0.0 on Windows 10).
  4. Navigate to that route (e.g. /training-plans or any page with an iframe).
  5. When the iframe fires its load event, 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/react 10.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

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions