@@ -78,13 +78,14 @@ const defaultNetworkOptions: NetworkRecordOptions = {
78
78
type Headers = Record < string , string > ;
79
79
80
80
type NetworkRequest = {
81
- requestUrl : string ;
82
- requestMethod : string ;
83
- requestInitiator : InitiatorType ;
81
+ url : string ;
82
+ method ?: string ;
83
+ initiatorType : InitiatorType ;
84
+ status ?: number ;
85
+ startTime : number ;
86
+ endTime : number ;
84
87
requestHeaders ?: Headers ;
85
88
requestBody ?: string | null ;
86
- responseStatus ?: number ;
87
- responseDuration : number ;
88
89
responseHeaders ?: Headers ;
89
90
responseBody ?: string | null ;
90
91
} ;
@@ -127,15 +128,12 @@ function initPerformanceObserver(
127
128
) ) ,
128
129
) ;
129
130
cb ( {
130
- requests : initialPerformanceEntries . map ( ( performanceEntry ) => ( {
131
- requestUrl : performanceEntry . name ,
132
- requestMethod : 'GET' ,
133
- requestInitiator : performanceEntry . initiatorType as InitiatorType ,
134
- responseStatus :
135
- 'responseStatus' in performanceEntry
136
- ? performanceEntry . responseStatus
137
- : undefined ,
138
- responseDuration : Math . round ( performanceEntry . duration ) ,
131
+ requests : initialPerformanceEntries . map ( ( entry ) => ( {
132
+ url : entry . name ,
133
+ initiatorType : entry . initiatorType as InitiatorType ,
134
+ status : 'responseStatus' in entry ? entry . responseStatus : undefined ,
135
+ startTime : Math . round ( entry . startTime ) ,
136
+ endTime : Math . round ( entry . responseEnd ) ,
139
137
} ) ) ,
140
138
isInitial : true ,
141
139
} ) ;
@@ -154,15 +152,12 @@ function initPerformanceObserver(
154
152
entry . initiatorType !== 'fetch' ) ,
155
153
) ;
156
154
cb ( {
157
- requests : performanceEntries . map ( ( performanceEntry ) => ( {
158
- requestUrl : performanceEntry . name ,
159
- requestMethod : 'GET' ,
160
- requestInitiator : performanceEntry . initiatorType as InitiatorType ,
161
- responseStatus :
162
- 'responseStatus' in performanceEntry
163
- ? performanceEntry . responseStatus
164
- : undefined ,
165
- responseDuration : Math . round ( performanceEntry . duration ) ,
155
+ requests : performanceEntries . map ( ( entry ) => ( {
156
+ url : entry . name ,
157
+ initiatorType : entry . initiatorType as InitiatorType ,
158
+ status : 'responseStatus' in entry ? entry . responseStatus : undefined ,
159
+ startTime : Math . round ( entry . startTime ) ,
160
+ endTime : Math . round ( entry . responseEnd ) ,
166
161
} ) ) ,
167
162
} ) ;
168
163
} ) ;
@@ -188,11 +183,11 @@ const getRequestPerformanceEntry = async (
188
183
) as PerformanceResourceTiming [ ] ;
189
184
const performanceEntry = findLast (
190
185
urlPerformanceEntries ,
191
- ( performanceEntry ) =>
192
- isResourceTiming ( performanceEntry ) &&
193
- performanceEntry . initiatorType === initiatorType &&
194
- ( ! after || performanceEntry . startTime >= after ) &&
195
- ( ! before || performanceEntry . startTime <= before ) ,
186
+ ( entry ) =>
187
+ isResourceTiming ( entry ) &&
188
+ entry . initiatorType === initiatorType &&
189
+ ( ! after || entry . startTime >= after ) &&
190
+ ( ! before || entry . startTime <= before ) ,
196
191
) ;
197
192
if ( ! performanceEntry ) {
198
193
await new Promise ( ( resolve ) => setTimeout ( resolve , 50 * attempt ) ) ;
@@ -322,15 +317,16 @@ function initXhrObserver(
322
317
after ,
323
318
before ,
324
319
)
325
- . then ( ( performanceEntry ) => {
320
+ . then ( ( entry ) => {
326
321
const request : NetworkRequest = {
327
- requestUrl : performanceEntry . name ,
328
- requestMethod : req . method ,
329
- requestInitiator : performanceEntry . initiatorType as InitiatorType ,
322
+ url : entry . name ,
323
+ method : req . method ,
324
+ initiatorType : entry . initiatorType as InitiatorType ,
325
+ status : xhr . status ,
326
+ startTime : Math . round ( entry . startTime ) ,
327
+ endTime : Math . round ( entry . responseEnd ) ,
330
328
requestHeaders : networkRequest . requestHeaders ,
331
329
requestBody : networkRequest . requestBody ,
332
- responseStatus : xhr . status ,
333
- responseDuration : performanceEntry . duration ,
334
330
responseHeaders : networkRequest . responseHeaders ,
335
331
responseBody : networkRequest . responseBody ,
336
332
} ;
@@ -409,7 +405,6 @@ function initFetchObserver(
409
405
after = win . performance . now ( ) ;
410
406
res = await originalFetch ( req ) ;
411
407
before = win . performance . now ( ) ;
412
- networkRequest . responseStatus = res . status ;
413
408
if ( recordResponseHeaders ) {
414
409
networkRequest . responseHeaders = { } ;
415
410
res . headers . forEach ( ( value , header ) => {
@@ -437,15 +432,16 @@ function initFetchObserver(
437
432
return res ;
438
433
} finally {
439
434
getRequestPerformanceEntry ( win , 'fetch' , req . url , after , before )
440
- . then ( ( performanceEntry ) => {
435
+ . then ( ( entry ) => {
441
436
const request : NetworkRequest = {
442
- requestUrl : performanceEntry . name ,
443
- requestMethod : req . method ,
444
- requestInitiator : performanceEntry . initiatorType as InitiatorType ,
437
+ url : entry . name ,
438
+ method : req . method ,
439
+ initiatorType : entry . initiatorType as InitiatorType ,
440
+ status : res ?. status ,
441
+ startTime : Math . round ( entry . startTime ) ,
442
+ endTime : Math . round ( entry . responseEnd ) ,
445
443
requestHeaders : networkRequest . requestHeaders ,
446
444
requestBody : networkRequest . requestBody ,
447
- responseStatus : res ?. status ,
448
- responseDuration : performanceEntry . duration ,
449
445
responseHeaders : networkRequest . responseHeaders ,
450
446
responseBody : networkRequest . responseBody ,
451
447
} ;
0 commit comments