@@ -233,6 +233,11 @@ function extendElementData( xpath, properties ) {
233
233
Object . assign ( elementData , properties ) ;
234
234
}
235
235
236
+ /**
237
+ * @typedef {{timestamp: number, creationDate: Date} } UrlMetricDebugData
238
+ * @typedef {{groups: Array<{url_metrics: Array<UrlMetricDebugData>}>} } CollectionDebugData
239
+ */
240
+
236
241
/**
237
242
* Detects the LCP element, loaded images, client viewport and store for future optimizations.
238
243
*
@@ -250,7 +255,7 @@ function extendElementData( xpath, properties ) {
250
255
* @param {URLMetricGroupStatus[] } args.urlMetricGroupStatuses URL Metric group statuses.
251
256
* @param {number } args.storageLockTTL The TTL (in seconds) for the URL Metric storage lock.
252
257
* @param {string } args.webVitalsLibrarySrc The URL for the web-vitals library.
253
- * @param {Object } [args.urlMetricGroupCollection] URL Metric group collection, when in debug mode.
258
+ * @param {CollectionDebugData } [args.urlMetricGroupCollection] URL Metric group collection, when in debug mode.
254
259
*/
255
260
export default async function detect ( {
256
261
minViewportAspectRatio,
@@ -269,7 +274,21 @@ export default async function detect( {
269
274
urlMetricGroupCollection,
270
275
} ) {
271
276
if ( isDebug ) {
272
- log ( 'Stored URL Metric group collection:' , urlMetricGroupCollection ) ;
277
+ const allUrlMetrics = /** @type Array<UrlMetricDebugData> */ [ ] ;
278
+ for ( const group of urlMetricGroupCollection . groups ) {
279
+ for ( const otherUrlMetric of group . url_metrics ) {
280
+ otherUrlMetric . creationDate = new Date (
281
+ otherUrlMetric . timestamp * 1000
282
+ ) ;
283
+ allUrlMetrics . push ( otherUrlMetric ) ;
284
+ }
285
+ }
286
+ log ( 'Stored URL Metric Group Collection:' , urlMetricGroupCollection ) ;
287
+ allUrlMetrics . sort ( ( a , b ) => b . timestamp - a . timestamp ) ;
288
+ log (
289
+ 'Stored URL Metrics in reverse chronological order:' ,
290
+ allUrlMetrics
291
+ ) ;
273
292
}
274
293
275
294
// Abort if the current viewport is not among those which need URL Metrics.
0 commit comments