1
1
import type { IWindow , listenerHandler , RecordPlugin } from '@rrweb/types' ;
2
2
import { patch } from '../../../utils' ;
3
- import { stringify , StringifyOptions } from '../../utils/stringify' ;
4
3
import { findLast } from '../../utils/find-last' ;
5
4
6
5
export type InitiatorType =
@@ -29,20 +28,8 @@ export type InitiatorType =
29
28
type NetworkRecordOptions = {
30
29
initiatorTypes ?: InitiatorType [ ] ;
31
30
ignoreRequestFn ?: ( data : NetworkRequest ) => boolean ;
32
- recordHeaders ?:
33
- | boolean
34
- | StringifyOptions
35
- | {
36
- request : boolean | StringifyOptions ;
37
- response : boolean | StringifyOptions ;
38
- } ;
39
- recordBody ?:
40
- | boolean
41
- | StringifyOptions
42
- | {
43
- request : boolean | StringifyOptions ;
44
- response : boolean | StringifyOptions ;
45
- } ;
31
+ recordHeaders ?: boolean | { request : boolean ; response : boolean } ;
32
+ recordBody ?: boolean | { request : boolean ; response : boolean } ;
46
33
recordInitialRequests ?: boolean ;
47
34
} ;
48
35
@@ -86,9 +73,9 @@ type NetworkRequest = {
86
73
startTime : number ;
87
74
endTime : number ;
88
75
requestHeaders ?: Headers ;
89
- requestBody ?: string | null ;
76
+ requestBody ?: unknown ;
90
77
responseHeaders ?: Headers ;
91
- responseBody ?: string | null ;
78
+ responseBody ?: unknown ;
92
79
} ;
93
80
94
81
export type NetworkData = {
@@ -265,12 +252,7 @@ function initXhrObserver(
265
252
if ( body === undefined || body === null ) {
266
253
networkRequest . requestBody = null ;
267
254
} else {
268
- networkRequest . requestBody = stringify (
269
- body ,
270
- typeof recordRequestBody === 'object'
271
- ? recordRequestBody
272
- : undefined ,
273
- ) ;
255
+ networkRequest . requestBody = body ;
274
256
}
275
257
}
276
258
after = win . performance . now ( ) ;
@@ -295,20 +277,10 @@ function initXhrObserver(
295
277
} ) ;
296
278
}
297
279
if ( recordResponseBody ) {
298
- if ( ! xhr . response ) {
280
+ if ( xhr . response === undefined || xhr . response === null ) {
299
281
networkRequest . responseBody = null ;
300
282
} else {
301
- try {
302
- const objBody = JSON . parse ( xhr . response as string ) as object ;
303
- networkRequest . responseBody = stringify (
304
- objBody ,
305
- typeof recordResponseBody === 'object'
306
- ? recordResponseBody
307
- : undefined ,
308
- ) ;
309
- } catch {
310
- networkRequest . responseBody = xhr . response as string ;
311
- }
283
+ networkRequest . responseBody = xhr . response ;
312
284
}
313
285
}
314
286
getRequestPerformanceEntry (
@@ -395,12 +367,7 @@ function initFetchObserver(
395
367
if ( req . body === undefined || req . body === null ) {
396
368
networkRequest . requestBody = null ;
397
369
} else {
398
- networkRequest . requestBody = stringify (
399
- req . body ,
400
- typeof recordRequestBody === 'object'
401
- ? recordRequestBody
402
- : undefined ,
403
- ) ;
370
+ networkRequest . requestBody = req . body ;
404
371
}
405
372
}
406
373
after = win . performance . now ( ) ;
@@ -413,21 +380,16 @@ function initFetchObserver(
413
380
} ) ;
414
381
}
415
382
if ( recordResponseBody ) {
416
- const reqBody = await res . clone ( ) . text ( ) ;
417
- if ( ! reqBody ) {
383
+ let body : string | undefined ;
384
+ try {
385
+ body = await res . clone ( ) . text ( ) ;
386
+ } catch {
387
+ //
388
+ }
389
+ if ( res . body === undefined || res . body === null ) {
418
390
networkRequest . responseBody = null ;
419
391
} else {
420
- try {
421
- const objBody = JSON . parse ( reqBody ) as object ;
422
- networkRequest . responseBody = stringify (
423
- objBody ,
424
- typeof recordResponseBody === 'object'
425
- ? recordResponseBody
426
- : undefined ,
427
- ) ;
428
- } catch {
429
- networkRequest . responseBody = reqBody ;
430
- }
392
+ networkRequest . responseBody = body ;
431
393
}
432
394
}
433
395
return res ;
0 commit comments