fix(browser): avoid Safari ReadableStream upload with fetch wrappers#3706
Open
dustinbyrne wants to merge 2 commits into
Open
fix(browser): avoid Safari ReadableStream upload with fetch wrappers#3706dustinbyrne wants to merge 2 commits into
dustinbyrne wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
dustinbyrne
commented
May 29, 2026
| addTracingHeaders(hostnames, distinctId, sessionManager, req.url, headers) | ||
|
|
||
| return originalFetch(req) | ||
| return originalFetch(url, { ...(init || {}), headers }) |
Contributor
Author
There was a problem hiding this comment.
Does anyone foresee any issues with spreading init like this?
Contributor
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
packages/browser/src/extensions/replay/external/network-plugin.ts:591-595
**ReadableStream body silently lost when body recording is enabled**
`_tryReadBody` calls `req.clone()`, which tees the underlying ReadableStream and replaces `req.body` with the first tee branch. Because `init.body` is the same `ReadableStream` object that `new Request(url, init)` stored internally, after the tee `init.body` points to the now-consumed original stream. For URL-string inputs the new path calls `originalFetch(url, init)`, so a locked/disturbed stream is passed as `init.body` — the browser's native fetch will throw or send an empty body. Before this PR `originalFetch(req)` was used, where `req.body` was already the live tee branch and the transmission succeeded. The regression is triggered only when `recordBody: true` is set and the caller passes a `ReadableStream` as the body, but in that scenario the request body is silently dropped.
Reviews (1): Last reviewed commit: "fix(browser): avoid Safari ReadableStrea..." | Re-trigger Greptile |
Contributor
Contributor
|
Size Change: +1.97 kB (+0.01%) Total Size: 16.5 MB
ℹ️ View Unchanged
|
f09d543 to
f917c7e
Compare
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.
Problem
Safari can throw
NotSupportedError: ReadableStream uploading is not supportedwhen PostHog fetch wrappers pass an internally-createdRequestobject to downstream fetch wrappers/interceptors. Those downstream wrappers can forwardrequest.body, which is aReadableStream, even when the app originally calledfetch(url, { method: 'POST', body: 'some string' }).Changes
Requestobjects downstream for originalfetch(url, init)calls in tracing headers and replay network capture wrappers.Requestfor originalfetch(Request)calls, since creating the clone can consume the original request body.Request.body.Validated locally:
pnpm --dir packages/browser typecheckpnpm --dir packages/browser exec eslint src/entrypoints/tracing-headers.ts src/extensions/replay/external/network-plugin.ts src/__tests__/extensions/replay/external/fetch-wrapper-invariants.test.ts playwright/mocked/fetch-post-body.spec.tscd packages/browser && pnpm exec jest src/__tests__/tracing-headers.test.ts src/__tests__/extensions/replay/external/fetch-wrapper-invariants.test.ts --runInBandcd packages/browser && pnpm exec playwright test playwright/mocked/fetch-post-body.spec.ts --project webkit --project chromium --project firefox --reporter=lineRelease info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file