This repository was archived by the owner on May 7, 2026. It is now read-only.
fix(record): handle SecurityError on ownerDocument access in Firefox#173
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(record): handle SecurityError on ownerDocument access in Firefox#173posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
In Firefox, reading `ownerDocument` on a node whose owning document has navigated cross-origin throws "Permission denied to access property 'ownerDocument'" (a SecurityError variant). The unguarded reads in `inDom`, `shadowHostInDom`, and `initAdoptedStyleSheetObserver` could abort the surrounding mutation/shadow-DOM observer callback, in the same family of failures fixed by 50bf563, e06b822, and a0e18f1 for `attachIframe`. - `inDom`/`shadowHostInDom`: read `ownerDocument` through a small helper that returns `null` if the access throws, so callers treat the node as not in the DOM rather than re-throwing. - `initAdoptedStyleSheetObserver`: wrap the `host.ownerDocument?.defaultView?.ShadowRoot` lookup and bail out with a no-op cleanup handler when a `SecurityError` is thrown. - Add regression tests covering both code paths with a node whose `ownerDocument` getter throws a `SecurityError`-named DOMException. Generated-By: PostHog Code Task-Id: 157b8b4a-321b-43ff-bb3b-dd519222e01e
Contributor
|
Size Change: +3.05 kB (+0.03%) 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
A new error-tracking issue surfaced on 2026-04-27 for
Error: Permission denied to access property "ownerDocument"originating in@posthog/rrweb-record0.0.60. The minified stack shows a tight loop of internal helper calls insiderrweb-record.jswith no application frames, in the same family as the cross-origin SecurityErrors fixed by 50bf563, e06b822, and a0e18f1.In Firefox, when a same-origin iframe later navigates cross-origin, reading
ownerDocumenton a node whose owning document is now cross-origin throws "Permission denied to access property 'ownerDocument'" (aSecurityError-namedDOMException). SeveralownerDocumentreads in the record bundle were not wrapped, so the throw escaped from low-level helpers and aborted the surrounding mutation / shadow-DOM observer callback — exactly the failure mode 50bf563 fixed forattachIframe.Changes
packages/rrweb/src/utils.ts— readownerDocumentthrough a smallsafeOwnerDocumenthelper that returnsnullif the access throws, soinDomandshadowHostInDomtreat the node as not in the DOM (the safe default for both callers inmutation.tspushAddand the patchedattachShadowinshadow-dom-manager.ts) instead of re-throwing.packages/rrweb/src/record/observer.ts— wrap thehost.ownerDocument?.defaultView?.ShadowRootlookup ininitAdoptedStyleSheetObserverwith a try/catch that swallowsDOMExceptionSecurityErrorand bails out with a no-op cleanup handler. Other exception types still propagate.packages/rrweb/test/util.test.tsandpackages/rrweb/test/record/observer.test.tsinstall anownerDocumentgetter that throws aSecurityError-namedDOMExceptionand assert the call sites do not re-throw — mirroring the regression test introduced in 50bf563.Test plan
pnpm --filter @posthog/rrweb retest test/util.test.ts test/record/observer.test.ts— all unit tests passpnpm --filter @posthog/rrweb check-types— cleanCreated with PostHog Code