Skip to content

Add isNativeFunction fast path to getImplementation#279

Open
7rulnik wants to merge 1 commit intogetsentry:sentry-v2from
7rulnik:is-native-check
Open

Add isNativeFunction fast path to getImplementation#279
7rulnik wants to merge 1 commit intogetsentry:sentry-v2from
7rulnik:is-native-check

Conversation

@7rulnik
Copy link
Copy Markdown

@7rulnik 7rulnik commented Apr 10, 2026

Summary

Add a fast path to getImplementation() in both rrweb and rrweb-snapshot that skips the sandbox iframe when window[name] is already a native browser function.

This matches the approach already used in @sentry-internal/browser-utils getNativeImplementation, but was missing from the two duplicated copies inside rrweb.

Problem

getImplementation() unconditionally creates a hidden <iframe>, pulls setTimeout / clearTimeout / requestAnimationFrame from its contentWindow, caches the reference with .bind(window), then removes the iframe from the DOM.

When the implementation on window is already native (the common case outside Angular/Zone.js), the iframe round-trip is pure overhead. Worse, it actively breaks in Firefox when combined with tools that patch timer globals (e.g. Playwright clock.install()): the cached function is bound to a destroyed iframe's execution context, and Firefox throws NS_ERROR_NOT_INITIALIZED on the next call.

See microsoft/playwright#40116 for the full reproduction and discussion. I believe it should be fixed in playwright but maintainer of it thinks differently. These changes allows at least to workaround this problem mimicking playwright overrides as native functions (basically patching toString) and not creating iframes in this case.

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