Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: capture network recording type #1296

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading