fix(replay): guard against missing XMLHttpRequest in network plugin#3440
Draft
posthog[bot] wants to merge 2 commits intomainfrom
Draft
fix(replay): guard against missing XMLHttpRequest in network plugin#3440posthog[bot] wants to merge 2 commits intomainfrom
posthog[bot] wants to merge 2 commits intomainfrom
Conversation
Accessing `win.XMLHttpRequest.prototype` throws in environments where `XMLHttpRequest` has been removed or shimmed away (exotic webviews, privacy tooling). The throw happens before the `patch` helper's try/catch, killing session recording init. Early-return the no-op listener when `win.XMLHttpRequest` (or its prototype) is nullish, matching the pattern used when `initiatorTypes` excludes `'xmlhttprequest'`. Generated-By: PostHog Code Task-Id: 3873cfb2-f560-476b-a5f2-4b51d03ddbf8
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Contributor
|
Size Change: +619 B (+0.01%) Total Size: 6.73 MB
ℹ️ View Unchanged
|
Generated-By: PostHog Code Task-Id: 3873cfb2-f560-476b-a5f2-4b51d03ddbf8
Contributor
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the |
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
initXhrObserverinpackages/browser/src/extensions/replay/external/network-plugin.tscallspatch(win.XMLHttpRequest.prototype, 'open', …)without checking thatwin.XMLHttpRequestexists. In environments wherewindow.XMLHttpRequesthas been stripped or shimmed away (exotic webviews, aggressive privacy tooling), the property access throws before thepatchhelper's internal try/catch can swallow it — killing session-recording initialization entirely.win.XMLHttpRequest(or its prototype) is nullish, mirroring the existing guard used wheninitiatorTypesexcludes'xmlhttprequest'.initFetchObserverin the same file is already safe: it passeswinitself as the patch source, andpatch()already guards withif (!(name in source))plus a try/catch around the entire body, so a missingwin.fetchcannot throw.Context
Surfaced by error tracking issue
019da1b8-837c-7af0-96e7-2d69da8324ab—TypeError: Cannot read properties of undefined (reading 'prototype')on 2026-04-18, one event / one user on Chrome with posthog-js 1.369.2. Single-occurrence signal, no regression or pattern, but a cheap hardening fix. Priority: P4.The companion signal
019da664-9dfe-7cd2-9394-343a74b18979(bufferBelongsToIframe) was investigated and ruled out of scope — its root cause lives in the external@posthog/rrweb-recorddependency, not in this repo.Test plan
network-plugin.test.tsasserting that starting the plugin withwindow.XMLHttpRequest = undefineddoes not throw.pnpm exec jest src/__tests__/extensions/replay/external/network-plugin.test.ts— 36/36 passing.Created with PostHog Code