コンテンツにスキップ

registerProxyFetch

このコンテンツはまだ日本語訳がありません。

registerProxyFetch(): void

Defined in: nextjs/registerProxyFetch.ts:49

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:

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

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

void