Add isNativeFunction fast path to getImplementation#279
Open
7rulnik wants to merge 1 commit intogetsentry:sentry-v2from
Open
Add isNativeFunction fast path to getImplementation#2797rulnik wants to merge 1 commit intogetsentry:sentry-v2from
7rulnik wants to merge 1 commit intogetsentry:sentry-v2from
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a fast path to
getImplementation()in bothrrwebandrrweb-snapshotthat skips the sandbox iframe whenwindow[name]is already a native browser function.This matches the approach already used in
@sentry-internal/browser-utilsgetNativeImplementation, but was missing from the two duplicated copies inside rrweb.Problem
getImplementation()unconditionally creates a hidden<iframe>, pullssetTimeout/clearTimeout/requestAnimationFramefrom itscontentWindow, caches the reference with.bind(window), then removes the iframe from the DOM.When the implementation on
windowis 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. Playwrightclock.install()): the cached function is bound to a destroyed iframe's execution context, and Firefox throwsNS_ERROR_NOT_INITIALIZEDon 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.