diff --git a/src/__tests__/extensions/replay/config.test.ts b/src/__tests__/extensions/replay/config.test.ts index 42f67c5f2..9f89b5840 100644 --- a/src/__tests__/extensions/replay/config.test.ts +++ b/src/__tests__/extensions/replay/config.test.ts @@ -216,6 +216,22 @@ describe('config', () => { }) }) + it('can amend the provided object', () => { + const posthogConfig = defaultConfig() + posthogConfig.session_recording.maskCapturedNetworkRequestFn = (data) => { + data.name = 'changed' + return data + } + const networkOptions = buildNetworkRequestOptions(posthogConfig, {}) + + const cleaned = networkOptions.maskRequestFn!({ + name: 'something', + } as Partial as CapturedNetworkRequest) + expect(cleaned).toEqual({ + name: 'changed', + }) + }) + it('should remove the Authorization header from requests even when a mask request fn is set', () => { const posthogConfig = defaultConfig() posthogConfig.session_recording.maskCapturedNetworkRequestFn = (data) => { diff --git a/src/types.ts b/src/types.ts index a1f729089..d037baa64 100644 --- a/src/types.ts +++ b/src/types.ts @@ -475,7 +475,12 @@ export type NetworkRequest = { // readonly name: string; // readonly startTime: DOMHighResTimeStamp; // NB: properties below here are ALPHA, don't rely on them, they may change without notice -export type CapturedNetworkRequest = Omit & { + +// we mirror PerformanceEntry since we read into this type from a PerformanceObserver, +// but we don't want to inherit its readonly-iness +type Writable = { -readonly [P in keyof T]: T[P] } + +export type CapturedNetworkRequest = Writable> & { // properties below here are ALPHA, don't rely on them, they may change without notice method?: string initiatorType?: InitiatorType