@@ -6,28 +6,35 @@ function sendWebVitals() {
66 return { } ;
77 }
88
9- let loafAttribution = {
10- debug_loaf_script_total_duration : 0
11- } ;
12-
139 // The last LoAF entry is usually the most relevant.
1410 const loaf = attribution . longAnimationFrameEntries . at ( - 1 ) ;
1511 const loafEndTime = loaf . startTime + loaf . duration ;
12+
13+ const loafAttribution = {
14+ // Stats for the LoAF entry itself.
15+ debug_loaf_entry_start_time : loaf . startTime ,
16+ debug_loaf_entry_end_time : loafEndTime ,
17+ debug_loaf_entry_work_duration : loaf . renderStart ? loaf . renderStart - loaf . startTime : loaf . duration ,
18+ debug_loaf_entry_render_duration : loaf . renderStart ? loafEndTime - loaf . renderStart : 0 ,
19+ debug_loaf_entry_total_forced_style_and_layout_duration : loaf . scripts . reduce ( ( sum , script ) => sum + script . forcedStyleAndLayoutDuration , 0 ) ,
20+ debug_loaf_entry_pre_layout_duration : loaf . styleAndLayoutStart ? loaf . styleAndLayoutStart - loaf . renderStart : 0 ,
21+ debug_loaf_entry_style_and_layout_duration : loaf . styleAndLayoutStart ? loafEndTime - loaf . styleAndLayoutStart : 0 ,
22+
23+ // LoAF metadata.
24+ debug_loaf_meta_length : loafEntriesLength ,
25+ debug_loaf_meta_script_length : loaf . scripts . length ,
26+ } ;
27+
28+ // Stats for the slowest script in the LoAF entry.
29+ let scriptAttribution = { } ;
30+ let slowestScriptDuration = 0 ;
1631 loaf . scripts . forEach ( script => {
17- if ( script . duration <= loafAttribution . debug_loaf_script_total_duration ) {
18- return ;
32+ if ( script . duration <= slowestScriptDuration ) {
33+ return { } ;
1934 }
20- loafAttribution = {
21- // Stats for the LoAF entry itself.
22- debug_loaf_entry_start_time : loaf . startTime ,
23- debug_loaf_entry_end_time : loafEndTime ,
24- debug_loaf_entry_work_duration : loaf . renderStart ? loaf . renderStart - loaf . startTime : loaf . duration ,
25- debug_loaf_entry_render_duration : loaf . renderStart ? loafEndTime - loaf . renderStart : 0 ,
26- debug_loaf_entry_total_forced_style_and_layout_duration : loaf . scripts . reduce ( ( sum , script ) => sum + script . forcedStyleAndLayoutDuration , 0 ) ,
27- debug_loaf_entry_pre_layout_duration : loaf . styleAndLayoutStart ? loaf . styleAndLayoutStart - loaf . renderStart : 0 ,
28- debug_loaf_entry_style_and_layout_duration : loaf . styleAndLayoutStart ? loafEndTime - loaf . styleAndLayoutStart : 0 ,
29-
30- // Stats for the longest script in the LoAF entry.
35+
36+ slowestScriptDuration = script . duration ;
37+ scriptAttribution = {
3138 debug_loaf_script_total_duration : script . duration ,
3239 debug_loaf_script_compile_duration : script . executionStart - script . startTime ,
3340 debug_loaf_script_exec_duration : script . startTime + script . duration - script . executionStart ,
@@ -37,9 +44,6 @@ function sendWebVitals() {
3744 debug_loaf_script_source_url : script . sourceURL ,
3845 debug_loaf_script_source_function_name : script . sourceFunctionName ,
3946 debug_loaf_script_source_char_position : script . sourceCharPosition ,
40-
41- // LoAF metadata.
42- debug_loaf_meta_length : loafEntriesLength ,
4347 }
4448 } ) ;
4549
@@ -73,7 +77,6 @@ function sendWebVitals() {
7377 debug_target : attribution . loadState || '(not set)' ,
7478 } ;
7579 break ;
76- case 'FID' :
7780 case 'INP' :
7881 const loafAttribution = getLoafAttribution ( attribution ) ;
7982 overrides = {
@@ -83,7 +86,7 @@ function sendWebVitals() {
8386 debug_target : attribution . interactionTarget || '(not set)' ,
8487 debug_interaction_delay : Math . round ( attribution . inputDelay ) ,
8588 debug_processing_duration : Math . round ( attribution . processingDuration ) ,
86- debug_presentation_delay : Math . round ( attribution . presentationDelay ) ,
89+ debug_presentation_delay : Math . round ( attribution . presentationDelay ) ,
8790 ...loafAttribution
8891 } ;
8992 break ;
@@ -161,7 +164,6 @@ function sendWebVitals() {
161164 webVitals . onLCP ( sendWebVitalsGAEvents ) ;
162165 webVitals . onCLS ( sendWebVitalsGAEvents ) ;
163166 webVitals . onTTFB ( sendWebVitalsGAEvents ) ;
164- webVitals . onFID ( sendWebVitalsGAEvents ) ;
165167 webVitals . onINP ( sendWebVitalsGAEvents ) ;
166168 } else {
167169 console . error ( 'Web Vitals is not loaded!!' ) ;
0 commit comments