55/**
66 * This handler stores page load metrics, including web vitals,
77 * and exports them in the shape of a map with the following shape:
8- * Map(FrameId -> Map(navigationID -> metrics) )
8+ * Map(FrameId -> Map(navigation -> metrics) )
99 *
10- * It also includes soft navigations as separate "navigations", though since soft
11- * navs use different events, the "navigationID" for them is created in this handler.
10+ * Includes soft navigations.
1211 *
1312 * It also exports all markers in a trace in an array.
1413 *
@@ -25,7 +24,6 @@ import type {HandlerName} from './types.js';
2524
2625// Small helpers to make the below type easier to read.
2726type FrameId = string ;
28- type NavigationId = string | `softnav-${string } `;
2927type AnyNavigationStart = Types . Events . NavigationStart | Types . Events . SoftNavigationStart ;
3028
3129/**
@@ -34,7 +32,7 @@ type AnyNavigationStart = Types.Events.NavigationStart|Types.Events.SoftNavigati
3432 * The metric scores include the event related to the metric as well as the data regarding
3533 * the score itself.
3634 */
37- let metricScoresByFrameId = new Map < FrameId , Map < NavigationId , Map < MetricName , MetricScore > > > ( ) ;
35+ let metricScoresByFrameId = new Map < FrameId , Map < AnyNavigationStart , Map < MetricName , MetricScore > > > ( ) ;
3836
3937/**
4038 * Page load events with no associated duration that happened in the
@@ -70,12 +68,6 @@ export function handleEvent(event: Types.Events.Event): void {
7068
7169function storePageLoadMetricAgainstNavigationId (
7270 navigation : AnyNavigationStart , event : Types . Events . PageLoadEvent ) : void {
73- const navigationId = Types . Events . isSoftNavigationStart ( navigation ) ?
74- `softnav-${ navigation . args . context . performanceTimelineNavigationId } ` :
75- navigation . args . data ?. navigationId ;
76- if ( ! navigationId ) {
77- throw new Error ( 'Navigation event unexpectedly had no navigation ID.' ) ;
78- }
7971 const frameId = getFrameIdForPageLoadEvent ( event ) ;
8072 const { rendererProcessesByFrame} = metaHandlerData ( ) ;
8173
@@ -102,15 +94,15 @@ function storePageLoadMetricAgainstNavigationId(
10294 const fcpTime = Types . Timing . Micro ( event . ts - navigation . ts ) ;
10395 const classification = scoreClassificationForFirstContentfulPaint ( fcpTime ) ;
10496 const metricScore = { event, metricName : MetricName . FCP , classification, navigation, timing : fcpTime } ;
105- storeMetricScore ( frameId , navigationId , metricScore ) ;
97+ storeMetricScore ( frameId , navigation , metricScore ) ;
10698 return ;
10799 }
108100
109101 if ( Types . Events . isFirstPaint ( event ) ) {
110102 const paintTime = Types . Timing . Micro ( event . ts - navigation . ts ) ;
111103 const classification = ScoreClassification . UNCLASSIFIED ;
112104 const metricScore = { event, metricName : MetricName . FP , classification, navigation, timing : paintTime } ;
113- storeMetricScore ( frameId , navigationId , metricScore ) ;
105+ storeMetricScore ( frameId , navigation , metricScore ) ;
114106 return ;
115107 }
116108
@@ -123,7 +115,7 @@ function storePageLoadMetricAgainstNavigationId(
123115 navigation,
124116 timing : dclTime ,
125117 } ;
126- storeMetricScore ( frameId , navigationId , metricScore ) ;
118+ storeMetricScore ( frameId , navigation , metricScore ) ;
127119 return ;
128120 }
129121
@@ -136,7 +128,7 @@ function storePageLoadMetricAgainstNavigationId(
136128 navigation,
137129 timing : ttiValue ,
138130 } ;
139- storeMetricScore ( frameId , navigationId , tti ) ;
131+ storeMetricScore ( frameId , navigation , tti ) ;
140132
141133 const tbtValue = Helpers . Timing . milliToMicro ( Types . Timing . Milli ( event . args . args . total_blocking_time_ms ) ) ;
142134 const tbt = {
@@ -146,7 +138,7 @@ function storePageLoadMetricAgainstNavigationId(
146138 navigation,
147139 timing : tbtValue ,
148140 } ;
149- storeMetricScore ( frameId , navigationId , tbt ) ;
141+ storeMetricScore ( frameId , navigation , tbt ) ;
150142 return ;
151143 }
152144
@@ -159,7 +151,7 @@ function storePageLoadMetricAgainstNavigationId(
159151 navigation,
160152 timing : loadTime ,
161153 } ;
162- storeMetricScore ( frameId , navigationId , metricScore ) ;
154+ storeMetricScore ( frameId , navigation , metricScore ) ;
163155 return ;
164156 }
165157
@@ -177,11 +169,11 @@ function storePageLoadMetricAgainstNavigationId(
177169 timing : lcpTime ,
178170 } ;
179171 const metricsByNavigation = Platform . MapUtilities . getWithDefault ( metricScoresByFrameId , frameId , ( ) => new Map ( ) ) ;
180- const metrics = Platform . MapUtilities . getWithDefault ( metricsByNavigation , navigationId , ( ) => new Map ( ) ) ;
172+ const metrics = Platform . MapUtilities . getWithDefault ( metricsByNavigation , navigation , ( ) => new Map ( ) ) ;
181173 const lastLCPCandidate = metrics . get ( MetricName . LCP ) ;
182174 if ( lastLCPCandidate === undefined ) {
183175 selectedLCPCandidateEvents . add ( lcp . event ) ;
184- storeMetricScore ( frameId , navigationId , lcp ) ;
176+ storeMetricScore ( frameId , navigation , lcp ) ;
185177 return ;
186178 }
187179 const lastLCPCandidateEvent = lastLCPCandidate . event ;
@@ -199,7 +191,7 @@ function storePageLoadMetricAgainstNavigationId(
199191 if ( lastCandidateIndex < candidateIndex ) {
200192 selectedLCPCandidateEvents . delete ( lastLCPCandidateEvent ) ;
201193 selectedLCPCandidateEvents . add ( lcp . event ) ;
202- storeMetricScore ( frameId , navigationId , lcp ) ;
194+ storeMetricScore ( frameId , navigation , lcp ) ;
203195 }
204196 return ;
205197 }
@@ -212,9 +204,9 @@ function storePageLoadMetricAgainstNavigationId(
212204 return Platform . assertNever ( event , `Unexpected event type: ${ event } ` ) ;
213205}
214206
215- function storeMetricScore ( frameId : string , navigationId : string , metricScore : MetricScore ) : void {
207+ function storeMetricScore ( frameId : string , navigation : AnyNavigationStart , metricScore : MetricScore ) : void {
216208 const metricsByNavigation = Platform . MapUtilities . getWithDefault ( metricScoresByFrameId , frameId , ( ) => new Map ( ) ) ;
217- const metrics = Platform . MapUtilities . getWithDefault ( metricsByNavigation , navigationId , ( ) => new Map ( ) ) ;
209+ const metrics = Platform . MapUtilities . getWithDefault ( metricsByNavigation , navigation , ( ) => new Map ( ) ) ;
218210 // If an entry with that metric name is present, delete it so that the new entry that
219211 // will replace it is added at the end of the map. This way we guarantee the map entries
220212 // are ordered in ASC manner by timestamp.
@@ -416,9 +408,9 @@ export interface PageLoadMetricsData {
416408 * The metric scores include the event related to the metric as well as the data regarding
417409 * the score itself.
418410 *
419- * Soft navigations have a faked NavigationId that starts with `softnav-` .
411+ * Includes soft navigations .
420412 */
421- metricScoresByFrameId : Map < string , Map < NavigationId , Map < MetricName , MetricScore > > > ;
413+ metricScoresByFrameId : Map < string , Map < AnyNavigationStart , Map < MetricName , MetricScore > > > ;
422414 /**
423415 * Page load events with no associated duration that happened in the
424416 * main frame.
0 commit comments