Skip to content

Commit

Permalink
fix: capture network recording type (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Jul 10, 2024
1 parent 22ab818 commit 0ee886e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/__tests__/extensions/replay/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CapturedNetworkRequest> 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) => {
Expand Down
7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PerformanceEntry, 'toJSON'> & {

// we mirror PerformanceEntry since we read into this type from a PerformanceObserver,
// but we don't want to inherit its readonly-iness
type Writable<T> = { -readonly [P in keyof T]: T[P] }

export type CapturedNetworkRequest = Writable<Omit<PerformanceEntry, 'toJSON'>> & {
// properties below here are ALPHA, don't rely on them, they may change without notice
method?: string
initiatorType?: InitiatorType
Expand Down

0 comments on commit 0ee886e

Please sign in to comment.