@@ -106,9 +106,9 @@ function storeTraceEventWithRequestId<K extends keyof TraceEventsForNetworkReque
106106 }
107107}
108108
109- function firstPositiveValueInList ( entries : number [ ] ) : number {
109+ function firstPositiveValueInList ( entries : Array < number | null > ) : number {
110110 for ( const entry of entries ) {
111- if ( entry > 0 ) {
111+ if ( entry && entry > 0 ) {
112112 return entry ;
113113 }
114114 }
@@ -204,7 +204,7 @@ export async function finalize(): Promise<void> {
204204 for ( const [ requestId , request ] of requestMap . entries ( ) ) {
205205 // If we have an incomplete set of events here, we choose to drop the network
206206 // request rather than attempt to synthesize the missing data.
207- if ( ! request . sendRequests || ! request . receiveResponse ) {
207+ if ( ! request . sendRequests ) {
208208 continue ;
209209 }
210210
@@ -244,12 +244,20 @@ export async function finalize(): Promise<void> {
244244 } ) ;
245245 }
246246
247+ const firstSendRequest = request . sendRequests [ 0 ] ;
248+ const finalSendRequest = request . sendRequests [ request . sendRequests . length - 1 ] ;
249+
250+ // We currently do not want to include data URI requests. We may revisit this in the future.
251+ if ( finalSendRequest . args . data . url . startsWith ( 'data:' ) ) {
252+ continue ;
253+ }
254+
247255 // If a ResourceFinish event with an encoded data length is received,
248256 // then the resource was not cached; it was fetched before it was
249257 // requested, e.g. because it was pushed in this navigation.
250258 const isPushedResource = request . resourceFinish ?. args . data . encodedDataLength !== 0 ;
251259 // This works around crbug.com/998397, which reports pushed resources, and resources served by a service worker as disk cached.
252- const isDiskCached = request . receiveResponse . args . data . fromCache &&
260+ const isDiskCached = ! ! request . receiveResponse && request . receiveResponse . args . data . fromCache &&
253261 ! request . receiveResponse . args . data . fromServiceWorker && ! isPushedResource ;
254262 // If the request contains a resourceMarkAsCached event, it was served from memory cache.
255263 // The timing data returned is from the original (uncached) request, which
@@ -265,15 +273,12 @@ export async function finalize(): Promise<void> {
265273 const isMemoryCached = request . resourceMarkAsCached !== undefined ;
266274 // If a request has `resourceMarkAsCached` field, the `timing` field is not correct.
267275 // So let's discard it and override to 0 (which will be handled in later logic if timing field is undefined).
268- const timing = isMemoryCached ? undefined : request . receiveResponse . args . data . timing ;
269- // If a non-cached request has no |timing| indicates data URLs , we ignore it.
270- if ( ! timing && ! isMemoryCached ) {
276+ const timing = isMemoryCached ? undefined : request . receiveResponse ? .args . data . timing ;
277+ // If a non-cached response has no |timing|, we ignore it. An example of this is chrome://new-page / about:blank .
278+ if ( request . receiveResponse && ! timing && ! isMemoryCached ) {
271279 continue ;
272280 }
273281
274- const firstSendRequest = request . sendRequests [ 0 ] ;
275- const finalSendRequest = request . sendRequests [ request . sendRequests . length - 1 ] ;
276-
277282 const initialPriority = finalSendRequest . args . data . priority ;
278283 let finalPriority = initialPriority ;
279284 if ( request . changePriority ) {
@@ -343,13 +348,14 @@ export async function finalize(): Promise<void> {
343348 // Otherwise it is whichever positive number comes first from the following timing info:
344349 // DNS start, Connection start, Send Start, or the time duration between our start time and
345350 // receiving a response.
346- const stalled = timing ? Types . Timing . Micro ( firstPositiveValueInList ( [
347- timing . dnsStart * MILLISECONDS_TO_MICROSECONDS ,
348- timing . connectStart * MILLISECONDS_TO_MICROSECONDS ,
349- timing . sendStart * MILLISECONDS_TO_MICROSECONDS ,
350- ( request . receiveResponse . ts - endRedirectTime ) ,
351- ] ) ) :
352- Types . Timing . Micro ( request . receiveResponse . ts - startTime ) ;
351+ const stalled = timing ?
352+ Types . Timing . Micro ( firstPositiveValueInList ( [
353+ timing . dnsStart * MILLISECONDS_TO_MICROSECONDS ,
354+ timing . connectStart * MILLISECONDS_TO_MICROSECONDS ,
355+ timing . sendStart * MILLISECONDS_TO_MICROSECONDS ,
356+ request . receiveResponse ? ( request . receiveResponse . ts - endRedirectTime ) : null ,
357+ ] ) ) :
358+ ( request . receiveResponse ? Types . Timing . Micro ( request . receiveResponse . ts - startTime ) : Types . Timing . Micro ( 0 ) ) ;
353359
354360 // Sending HTTP request
355361 // =======================
@@ -373,8 +379,9 @@ export async function finalize(): Promise<void> {
373379 Types . Timing . Micro (
374380 timing . requestTime * SECONDS_TO_MICROSECONDS + timing . receiveHeadersEnd * MILLISECONDS_TO_MICROSECONDS ) :
375381 startTime ;
376- const download = timing ? Types . Timing . Micro ( ( ( finishTime || downloadStart ) - downloadStart ) ) :
377- Types . Timing . Micro ( endTime - request . receiveResponse . ts ) ;
382+ const download = timing ? Types . Timing . Micro ( ( ( finishTime || downloadStart ) - downloadStart ) ) :
383+ request . receiveResponse ? Types . Timing . Micro ( endTime - request . receiveResponse . ts ) :
384+ Types . Timing . Micro ( 0 ) ;
378385
379386 const totalTime = Types . Timing . Micro ( networkDuration + processingDuration ) ;
380387
@@ -435,30 +442,31 @@ export async function finalize(): Promise<void> {
435442 decodedBodyLength,
436443 encodedDataLength,
437444 frame,
438- fromServiceWorker : request . receiveResponse . args . data . fromServiceWorker ,
445+ fromServiceWorker : request . receiveResponse ? .args . data . fromServiceWorker ,
439446 isLinkPreload : finalSendRequest . args . data . isLinkPreload || false ,
440- mimeType : request . receiveResponse . args . data . mimeType ,
447+ mimeType : request . receiveResponse ? .args . data . mimeType ?? '' ,
441448 priority : finalPriority ,
442449 initialPriority,
443- protocol : request . receiveResponse . args . data . protocol ?? 'unknown' ,
450+ protocol : request . receiveResponse ? .args . data . protocol ?? 'unknown' ,
444451 redirects,
445452 // In the event the property isn't set, assume non-blocking.
446453 renderBlocking : renderBlocking ?? 'non_blocking' ,
447454 requestId,
448455 requestingFrameUrl,
449456 requestMethod : finalSendRequest . args . data . requestMethod ,
450457 resourceType : finalSendRequest . args . data . resourceType ?? Protocol . Network . ResourceType . Other ,
451- statusCode : request . receiveResponse . args . data . statusCode ,
452- responseHeaders : request . receiveResponse . args . data . headers || [ ] ,
458+ statusCode : request . receiveResponse ? .args . data . statusCode ?? 0 ,
459+ responseHeaders : request . receiveResponse ? .args . data . headers ?? null ,
453460 fetchPriorityHint : finalSendRequest . args . data . fetchPriorityHint ?? 'auto' ,
454461 initiator : finalSendRequest . args . data . initiator ,
455462 stackTrace : finalSendRequest . args . data . stackTrace ,
456463 timing,
457464 url,
458465 failed : request . resourceFinish ?. args . data . didFail ?? false ,
459466 finished : Boolean ( request . resourceFinish ) ,
460- connectionId : request . receiveResponse . args . data . connectionId ,
461- connectionReused : request . receiveResponse . args . data . connectionReused ,
467+ hasResponse : Boolean ( request . receiveResponse ) ,
468+ connectionId : request . receiveResponse ?. args . data . connectionId ,
469+ connectionReused : request . receiveResponse ?. args . data . connectionReused ,
462470 } ,
463471 } ,
464472 cat : 'loading' ,
0 commit comments