|
1 | 1 | function sendWebVitals() { |
2 | | - function getLoafAttribution(attribution) { |
3 | | - if (!attribution) { |
4 | | - return {}; |
5 | | - } |
6 | | - |
7 | | - const entry = attribution.eventEntry; |
8 | 2 |
|
9 | | - if (!entry) { |
10 | | - return {}; |
11 | | - } |
12 | | - |
13 | | - if (!PerformanceObserver.supportedEntryTypes.includes('long-animation-frame')) { |
| 3 | + function getLoafAttribution(attribution) { |
| 4 | + if (!attribution?.longAnimationFrameEntries) { |
14 | 5 | return {}; |
15 | 6 | } |
16 | 7 |
|
17 | 8 | let loafAttribution = { |
18 | 9 | debug_loaf_script_total_duration: 0 |
19 | 10 | }; |
20 | 11 |
|
21 | | - const longAnimationFrames = performance.getEntriesByType('long-animation-frame'); |
22 | | - longAnimationFrames.filter(loaf => { |
23 | | - // LoAFs that intersect with the event. |
24 | | - return entry.startTime < (loaf.startTime + loaf.duration) && loaf.startTime < (entry.startTime + entry.duration); |
25 | | - }).forEach(loaf => { |
26 | | - const loafEndTime = loaf.startTime + loaf.duration; |
27 | | - loaf.scripts.forEach(script => { |
28 | | - if (script.duration <= loafAttribution.debug_loaf_script_total_duration) { |
29 | | - return; |
30 | | - } |
31 | | - loafAttribution = { |
32 | | - // Stats for the LoAF entry itself. |
33 | | - debug_loaf_entry_start_time: loaf.startTime, |
34 | | - debug_loaf_entry_end_time: loafEndTime, |
35 | | - debug_loaf_entry_work_duration: loaf.renderStart ? loaf.renderStart - loaf.startTime : loaf.duration, |
36 | | - debug_loaf_entry_render_duration: loaf.renderStart ? loafEndTime - loaf.renderStart : 0, |
37 | | - debug_loaf_entry_total_forced_style_and_layout_duration: loaf.scripts.reduce((sum, script) => sum + script.forcedStyleAndLayoutDuration, 0), |
38 | | - debug_loaf_entry_pre_layout_duration: loaf.styleAndLayoutStart ? loaf.styleAndLayoutStart - loaf.renderStart : 0, |
39 | | - debug_loaf_entry_style_and_layout_duration: loaf.styleAndLayoutStart ? loafEndTime - loaf.styleAndLayoutStart : 0, |
40 | | - |
41 | | - // Stats for the longest script in the LoAF entry. |
42 | | - debug_loaf_script_total_duration: script.duration, |
43 | | - debug_loaf_script_compile_duration: script.executionStart - script.startTime, |
44 | | - debug_loaf_script_exec_duration: script.startTime + script.duration - script.executionStart, |
45 | | - debug_loaf_script_source: script.sourceLocation || script.invoker || script.name, // TODO: remove after Chrome 123 |
46 | | - debug_loaf_script_type: script.invokerType || script.type, // TODO: remove `|| script.type` after Chrome 123 |
47 | | - // New in Chrome 122/123 (will be null until then) |
48 | | - debug_loaf_script_invoker: script.invoker, |
49 | | - debug_loaf_script_source_url: script.sourceURL, |
50 | | - debug_loaf_script_source_function_name: script.sourceFunctionName, |
51 | | - debug_loaf_script_source_char_position: script.sourceCharPosition, |
52 | | - |
53 | | - // LoAF metadata. |
54 | | - debug_loaf_meta_length: longAnimationFrames.length, |
55 | | - } |
56 | | - }); |
| 12 | + // The last LoAF entry is usually the most relevant. |
| 13 | + const loaf = attribution.longAnimationFrameEntries.at(-1) |
| 14 | + const loafEndTime = loaf.startTime + loaf.duration; |
| 15 | + loaf.scripts.forEach(script => { |
| 16 | + if (script.duration <= loafAttribution.debug_loaf_script_total_duration) { |
| 17 | + return; |
| 18 | + } |
| 19 | + loafAttribution = { |
| 20 | + // Stats for the LoAF entry itself. |
| 21 | + debug_loaf_entry_start_time: loaf.startTime, |
| 22 | + debug_loaf_entry_end_time: loafEndTime, |
| 23 | + debug_loaf_entry_work_duration: loaf.renderStart ? loaf.renderStart - loaf.startTime : loaf.duration, |
| 24 | + debug_loaf_entry_render_duration: loaf.renderStart ? loafEndTime - loaf.renderStart : 0, |
| 25 | + debug_loaf_entry_total_forced_style_and_layout_duration: loaf.scripts.reduce((sum, script) => sum + script.forcedStyleAndLayoutDuration, 0), |
| 26 | + debug_loaf_entry_pre_layout_duration: loaf.styleAndLayoutStart ? loaf.styleAndLayoutStart - loaf.renderStart : 0, |
| 27 | + debug_loaf_entry_style_and_layout_duration: loaf.styleAndLayoutStart ? loafEndTime - loaf.styleAndLayoutStart : 0, |
| 28 | + |
| 29 | + // Stats for the longest script in the LoAF entry. |
| 30 | + debug_loaf_script_total_duration: script.duration, |
| 31 | + debug_loaf_script_compile_duration: script.executionStart - script.startTime, |
| 32 | + debug_loaf_script_exec_duration: script.startTime + script.duration - script.executionStart, |
| 33 | + debug_loaf_script_forced_style_and_layout_duration: script.forcedStyleAndLayoutDuration, |
| 34 | + debug_loaf_script_type: script.invokerType, |
| 35 | + debug_loaf_script_invoker: script.invoker, |
| 36 | + debug_loaf_script_source_url: script.sourceURL, |
| 37 | + debug_loaf_script_source_function_name: script.sourceFunctionName, |
| 38 | + debug_loaf_script_source_char_position: script.sourceCharPosition, |
| 39 | + |
| 40 | + // LoAF metadata. |
| 41 | + debug_loaf_meta_length: attribution.longAnimationFrameEntries.length, |
| 42 | + } |
57 | 43 | }); |
58 | 44 |
|
59 | 45 | if (!loafAttribution.debug_loaf_script_total_duration) { |
@@ -91,18 +77,15 @@ function sendWebVitals() { |
91 | 77 | case 'INP': |
92 | 78 | const loafAttribution = getLoafAttribution(attribution); |
93 | 79 | overrides = { |
94 | | - debug_event: attribution.eventType, |
95 | | - debug_time: Math.round(attribution.eventTime), |
| 80 | + debug_event: attribution.interactionType, |
| 81 | + debug_time: Math.round(attribution.interactionTime), |
96 | 82 | debug_load_state: attribution.loadState, |
97 | | - debug_target: attribution.eventTarget || '(not set)', |
| 83 | + debug_target: attribution.interactionTarget || '(not set)', |
| 84 | + debug_interaction_delay: Math.round(attribution.inputDelay), |
| 85 | + debug_processing_duration: Math.round(attribution.processingDuration), |
| 86 | + debug_presentation_delay: Math.round(attribution.presentationDelay), |
98 | 87 | ...loafAttribution |
99 | 88 | }; |
100 | | - if (!attribution.eventEntry) { |
101 | | - break; |
102 | | - } |
103 | | - overrides.debug_interaction_delay = Math.round(attribution.eventEntry.processingStart - attribution.eventEntry.startTime); |
104 | | - overrides.debug_processing_time = Math.round(attribution.eventEntry.processingEnd - attribution.eventEntry.processingStart); |
105 | | - overrides.debug_presentation_delay = Math.round(attribution.eventEntry.duration + attribution.eventEntry.startTime - attribution.eventEntry.processingEnd); |
106 | 89 | break; |
107 | 90 | case 'LCP': |
108 | 91 | overrides = { |
|
0 commit comments