This repository was archived by the owner on May 7, 2026. It is now read-only.
fix(record): guard undefined slots in findAndRemoveIframeBuffer#174
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(record): guard undefined slots in findAndRemoveIframeBuffer#174posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
A cross-origin iframe pagehide (reCAPTCHA, PDFTron WebViewer) was crashing the recorder with "Cannot read properties of undefined (reading 'bufferBelongsToIframe')" because findAndRemoveIframeBuffer iterated mutationBuffers with no nullish guard while sibling code paths can splice the same array. Generated-By: PostHog Code Task-Id: e6152cf5-3de7-42db-863f-35da4aff0e45
Contributor
|
Size Change: +234 B (0%) Total Size: 10.9 MB
ℹ️ View Unchanged
|
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Cross-origin iframes (reCAPTCHA, PDFTron WebViewer) were crashing the session-replay recorder on
pagehidewith:findAndRemoveIframeBufferinpackages/rrweb/src/record/observer.tsiteratedmutationBuffersfrom the tail and dereferencedbuf.bufferBelongsToIframe(iframeEl)without checking thatbufwas defined. The function is invoked from the iframepagehidelistener, which can race with other code paths that splicemutationBuffers(e.g.shadow-dom-manager.ts,observer.ts); when a slot isundefined, the property access throws.findAndRemoveIframeBufferandMutationBuffer.bufferBelongsToIframewere introduced together in #157 (adopting upstream rrweb #1755). The follow-up #167 only patched a sibling null-deref iniframe-manager.ts:119, leaving this loop unguarded.Fix
buf?.bufferBelongsToIframe(iframeEl)) so undefined slots are skipped instead of throwing.packages/rrweb/test/record/memory-leaks.test.tsthat seedsmutationBufferswith anundefinedslot and verifiesfindAndRemoveIframeBufferdoes not throw and still removes the matching buffer.Verified the new test reproduces the original
TypeErrorwhen the guard is removed.Test plan
pnpm vitest run test/record/memory-leaks.test.ts— all 23 tests passtsc -noEmitpassesCreated with PostHog Code