# registerProxyFetch

Canonical: <https://test-proxy-recorder.dev/docs/reference/api/functions/registerproxyfetch/>
Docs index: <https://test-proxy-recorder.dev/docs/> · All docs as one file: <https://test-proxy-recorder.dev/llms-full.txt>

---

> **registerProxyFetch**(): `void`

Defined in: [nextjs/registerProxyFetch.ts:49](https://github.com/asmyshlyaev177/test-proxy-recorder/blob/d1bacb3b39a3cf6f7f5a5391a8201868e4629861/packages/test-proxy-recorder/src/nextjs/registerProxyFetch.ts#L49)

Patch the global `fetch` so every server-side request carries the current
session's recording id (`x-test-rcrd-id`).

Playwright sets that header on the browser, so document navigations reach SSR.
But a Server Component's own `fetch()` to the proxy is a fresh request that
doesn't inherit it — under parallel replay the proxy then can't tell which
recording to serve. `setNextProxyHeaders` middleware covers most cases, but on
the Edge runtime its context differs from the one rendering your routes.
Patching `fetch` once, in the right place, covers everything.

Call it at the top level of your root layout (`app/layout.tsx`) — not
`instrumentation.ts`, whose `register()` runs in a different context on the
Edge runtime and patches the wrong `globalThis.fetch`:

```ts
import { registerProxyFetch } from 'test-proxy-recorder/nextjs';
registerProxyFetch();
```

Idempotent. No-op in production unless `TEST_PROXY_RECORDER_ENABLED` is set.

## Returns

`void`
