lighthouse 11.7.0-dev.20240408 → 11.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/CONTRIBUTING.md +2 -2
  2. package/cli/test/smokehouse/core-tests.js +2 -0
  3. package/core/audits/accessibility/duplicate-id-active.d.ts +10 -0
  4. package/core/audits/accessibility/duplicate-id-active.js +42 -0
  5. package/core/audits/accessibility/target-size.js +1 -0
  6. package/core/audits/byte-efficiency/byte-efficiency-audit.d.ts +16 -0
  7. package/core/audits/byte-efficiency/byte-efficiency-audit.js +38 -1
  8. package/core/audits/byte-efficiency/offscreen-images.d.ts +11 -0
  9. package/core/audits/byte-efficiency/offscreen-images.js +15 -0
  10. package/core/audits/dobetterweb/uses-http2.d.ts +13 -0
  11. package/core/audits/dobetterweb/uses-http2.js +34 -2
  12. package/core/audits/layout-shift-elements.d.ts +16 -0
  13. package/core/audits/layout-shift-elements.js +101 -0
  14. package/core/audits/no-unload-listeners.d.ts +16 -0
  15. package/core/audits/no-unload-listeners.js +86 -0
  16. package/core/audits/preload-fonts.d.ts +5 -1
  17. package/core/audits/preload-fonts.js +10 -1
  18. package/core/audits/script-elements-test-audit.d.ts +14 -0
  19. package/core/audits/script-elements-test-audit.js +29 -0
  20. package/core/audits/seo/is-crawlable.d.ts +1 -2
  21. package/core/audits/seo/plugins.d.ts +15 -0
  22. package/core/audits/seo/plugins.js +150 -0
  23. package/core/audits/seo/tap-targets.d.ts +50 -0
  24. package/core/audits/seo/tap-targets.js +352 -0
  25. package/core/audits/uses-rel-preload.d.ts +5 -1
  26. package/core/audits/uses-rel-preload.js +11 -1
  27. package/core/audits/work-during-interaction.d.ts +2 -2
  28. package/core/audits/work-during-interaction.js +2 -2
  29. package/core/computed/js-bundles.d.ts +1 -1
  30. package/core/computed/metrics/lantern-first-contentful-paint.d.ts +82 -13
  31. package/core/computed/metrics/lantern-first-contentful-paint.js +178 -15
  32. package/core/computed/metrics/lantern-first-meaningful-paint.d.ts +12 -13
  33. package/core/computed/metrics/lantern-first-meaningful-paint.js +49 -10
  34. package/core/computed/metrics/lantern-interactive.d.ts +21 -13
  35. package/core/computed/metrics/lantern-interactive.js +84 -11
  36. package/core/computed/metrics/lantern-largest-contentful-paint.d.ts +25 -13
  37. package/core/computed/metrics/lantern-largest-contentful-paint.js +80 -12
  38. package/core/computed/metrics/lantern-max-potential-fid.d.ts +24 -13
  39. package/core/computed/metrics/lantern-max-potential-fid.js +64 -11
  40. package/core/computed/metrics/lantern-metric.d.ts +18 -9
  41. package/core/computed/metrics/lantern-metric.js +31 -13
  42. package/core/computed/metrics/lantern-speed-index.d.ts +32 -13
  43. package/core/computed/metrics/lantern-speed-index.js +116 -12
  44. package/core/computed/metrics/lantern-total-blocking-time.d.ts +25 -13
  45. package/core/computed/metrics/lantern-total-blocking-time.js +94 -10
  46. package/core/computed/metrics/metric.js +3 -1
  47. package/core/computed/module-duplication.d.ts +1 -1
  48. package/core/computed/page-dependency-graph.js +1 -2
  49. package/core/config/default-config.js +74 -46
  50. package/core/config/experimental-config.js +0 -11
  51. package/core/config/metrics-to-audits.d.ts +19 -0
  52. package/core/config/metrics-to-audits.js +62 -0
  53. package/core/gather/gatherers/accessibility.js +3 -1
  54. package/core/gather/gatherers/global-listeners.d.ts +27 -0
  55. package/core/gather/gatherers/global-listeners.js +108 -0
  56. package/core/gather/gatherers/script-elements.d.ts +21 -0
  57. package/core/gather/gatherers/script-elements.js +100 -0
  58. package/core/gather/gatherers/seo/embedded-content.d.ts +10 -0
  59. package/core/gather/gatherers/seo/embedded-content.js +63 -0
  60. package/core/gather/gatherers/seo/tap-targets.d.ts +21 -0
  61. package/core/gather/gatherers/seo/tap-targets.js +389 -0
  62. package/core/gather/gatherers/trace-elements.d.ts +10 -0
  63. package/core/gather/gatherers/trace-elements.js +19 -0
  64. package/core/lib/lantern/page-dependency-graph.d.ts +4 -4
  65. package/core/lib/lantern/page-dependency-graph.js +5 -5
  66. package/core/lib/lighthouse-compatibility.js +10 -53
  67. package/dist/report/bundle.esm.js +1 -1
  68. package/dist/report/flow.js +14 -14
  69. package/dist/report/standalone.js +1 -1
  70. package/flow-report/src/summary/category.tsx +12 -10
  71. package/package.json +1 -1
  72. package/report/renderer/performance-category-renderer.d.ts +7 -0
  73. package/report/renderer/performance-category-renderer.js +11 -1
  74. package/report/renderer/report-utils.js +10 -13
  75. package/shared/localization/locales/ar-XB.json +64 -1
  76. package/shared/localization/locales/ar.json +64 -1
  77. package/shared/localization/locales/bg.json +64 -1
  78. package/shared/localization/locales/ca.json +64 -1
  79. package/shared/localization/locales/cs.json +64 -1
  80. package/shared/localization/locales/da.json +64 -1
  81. package/shared/localization/locales/de.json +64 -1
  82. package/shared/localization/locales/el.json +64 -1
  83. package/shared/localization/locales/en-GB.json +64 -1
  84. package/shared/localization/locales/en-US.json +65 -2
  85. package/shared/localization/locales/en-XA.json +64 -1
  86. package/shared/localization/locales/en-XL.json +65 -2
  87. package/shared/localization/locales/es-419.json +64 -1
  88. package/shared/localization/locales/es.json +64 -1
  89. package/shared/localization/locales/fi.json +64 -1
  90. package/shared/localization/locales/fil.json +64 -1
  91. package/shared/localization/locales/fr.json +64 -1
  92. package/shared/localization/locales/he.json +64 -1
  93. package/shared/localization/locales/hi.json +64 -1
  94. package/shared/localization/locales/hr.json +64 -1
  95. package/shared/localization/locales/hu.json +64 -1
  96. package/shared/localization/locales/id.json +64 -1
  97. package/shared/localization/locales/it.json +64 -1
  98. package/shared/localization/locales/ja.json +64 -1
  99. package/shared/localization/locales/ko.json +64 -1
  100. package/shared/localization/locales/lt.json +64 -1
  101. package/shared/localization/locales/lv.json +64 -1
  102. package/shared/localization/locales/nl.json +64 -1
  103. package/shared/localization/locales/no.json +64 -1
  104. package/shared/localization/locales/pl.json +64 -1
  105. package/shared/localization/locales/pt-PT.json +64 -1
  106. package/shared/localization/locales/pt.json +64 -1
  107. package/shared/localization/locales/ro.json +64 -1
  108. package/shared/localization/locales/ru.json +64 -1
  109. package/shared/localization/locales/sk.json +64 -1
  110. package/shared/localization/locales/sl.json +64 -1
  111. package/shared/localization/locales/sr-Latn.json +64 -1
  112. package/shared/localization/locales/sr.json +64 -1
  113. package/shared/localization/locales/sv.json +64 -1
  114. package/shared/localization/locales/ta.json +64 -1
  115. package/shared/localization/locales/te.json +64 -1
  116. package/shared/localization/locales/th.json +64 -1
  117. package/shared/localization/locales/tr.json +64 -1
  118. package/shared/localization/locales/uk.json +64 -1
  119. package/shared/localization/locales/vi.json +64 -1
  120. package/shared/localization/locales/zh-HK.json +64 -1
  121. package/shared/localization/locales/zh-TW.json +64 -1
  122. package/shared/localization/locales/zh.json +64 -1
  123. package/tsconfig.json +0 -1
  124. package/types/artifacts.d.ts +17 -3
  125. package/types/config.d.ts +1 -0
  126. package/types/lhr/audit-details.d.ts +4 -9
  127. package/types/lhr/lhr.d.ts +2 -0
  128. package/core/lib/lantern/metrics/first-contentful-paint.d.ts +0 -79
  129. package/core/lib/lantern/metrics/first-contentful-paint.js +0 -200
  130. package/core/lib/lantern/metrics/first-meaningful-paint.d.ts +0 -6
  131. package/core/lib/lantern/metrics/first-meaningful-paint.js +0 -66
  132. package/core/lib/lantern/metrics/interactive.d.ts +0 -26
  133. package/core/lib/lantern/metrics/interactive.js +0 -112
  134. package/core/lib/lantern/metrics/largest-contentful-paint.d.ts +0 -19
  135. package/core/lib/lantern/metrics/largest-contentful-paint.js +0 -108
  136. package/core/lib/lantern/metrics/max-potential-fid.d.ts +0 -30
  137. package/core/lib/lantern/metrics/max-potential-fid.js +0 -92
  138. package/core/lib/lantern/metrics/speed-index.d.ts +0 -38
  139. package/core/lib/lantern/metrics/speed-index.js +0 -145
  140. package/core/lib/lantern/metrics/total-blocking-time.d.ts +0 -31
  141. package/core/lib/lantern/metrics/total-blocking-time.js +0 -128
@@ -1,200 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2024 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import * as Lantern from '../types/lantern.js';
8
- import {Metric} from '../metric.js';
9
- import {BaseNode} from '../base-node.js';
10
-
11
- /** @typedef {import('../base-node.js').Node} Node */
12
- /** @template T @typedef {import('../network-node.js').NetworkNode<T>} NetworkNode */
13
- /** @typedef {import('../cpu-node.js').CPUNode} CpuNode */
14
-
15
- class FirstContentfulPaint extends Metric {
16
- /**
17
- * @return {Lantern.Simulation.MetricCoefficients}
18
- */
19
- static get COEFFICIENTS() {
20
- return {
21
- intercept: 0,
22
- optimistic: 0.5,
23
- pessimistic: 0.5,
24
- };
25
- }
26
-
27
- /**
28
- * @template T
29
- * @typedef FirstPaintBasedGraphOpts
30
- * @property {number} cutoffTimestamp The timestamp used to filter out tasks that occured after
31
- * our paint of interest. Typically this is First Contentful Paint or First Meaningful Paint.
32
- * @property {function(NetworkNode<T>):boolean} treatNodeAsRenderBlocking The function that determines
33
- * which resources should be considered *possibly* render-blocking.
34
- * @property {(function(CpuNode):boolean)=} additionalCpuNodesToTreatAsRenderBlocking The function that
35
- * determines which CPU nodes should also be included in our blocking node IDs set,
36
- * beyond what getRenderBlockingNodeData() already includes.
37
- */
38
-
39
- /**
40
- * This function computes the set of URLs that *appeared* to be render-blocking based on our filter,
41
- * *but definitely were not* render-blocking based on the timing of their EvaluateScript task.
42
- * It also computes the set of corresponding CPU node ids that were needed for the paint at the
43
- * given timestamp.
44
- *
45
- * @template [T=unknown]
46
- * @param {Node} graph
47
- * @param {FirstPaintBasedGraphOpts<T>} opts
48
- * @return {{definitelyNotRenderBlockingScriptUrls: Set<string>, renderBlockingCpuNodeIds: Set<string>}}
49
- */
50
- static getRenderBlockingNodeData(
51
- graph,
52
- {cutoffTimestamp, treatNodeAsRenderBlocking, additionalCpuNodesToTreatAsRenderBlocking}
53
- ) {
54
- /** @type {Map<string, CpuNode>} A map of blocking script URLs to the earliest EvaluateScript task node that executed them. */
55
- const scriptUrlToNodeMap = new Map();
56
-
57
- /** @type {Array<CpuNode>} */
58
- const cpuNodes = [];
59
- graph.traverse(node => {
60
- if (node.type === BaseNode.TYPES.CPU) {
61
- // A task is *possibly* render blocking if it *started* before cutoffTimestamp.
62
- // We use startTime here because the paint event can be *inside* the task that was render blocking.
63
- if (node.startTime <= cutoffTimestamp) cpuNodes.push(node);
64
-
65
- // Build our script URL map to find the earliest EvaluateScript task node.
66
- const scriptUrls = node.getEvaluateScriptURLs();
67
- for (const url of scriptUrls) {
68
- // Use the earliest CPU node we find.
69
- const existing = scriptUrlToNodeMap.get(url) || node;
70
- scriptUrlToNodeMap.set(url, node.startTime < existing.startTime ? node : existing);
71
- }
72
- }
73
- });
74
-
75
- cpuNodes.sort((a, b) => a.startTime - b.startTime);
76
-
77
- // A script is *possibly* render blocking if it finished loading before cutoffTimestamp.
78
- const possiblyRenderBlockingScriptUrls = Metric.getScriptUrls(graph, node => {
79
- // The optimistic LCP treatNodeAsRenderBlocking fn wants to exclude some images in the graph,
80
- // but here it only receives scripts to evaluate. It's a no-op in this case, but it will
81
- // matter below in the getFirstPaintBasedGraph clone operation.
82
- return node.endTime <= cutoffTimestamp && treatNodeAsRenderBlocking(node);
83
- });
84
-
85
- // A script is *definitely not* render blocking if its EvaluateScript task started after cutoffTimestamp.
86
- /** @type {Set<string>} */
87
- const definitelyNotRenderBlockingScriptUrls = new Set();
88
- /** @type {Set<string>} */
89
- const renderBlockingCpuNodeIds = new Set();
90
- for (const url of possiblyRenderBlockingScriptUrls) {
91
- // Lookup the CPU node that had the earliest EvaluateScript for this URL.
92
- const cpuNodeForUrl = scriptUrlToNodeMap.get(url);
93
-
94
- // If we can't find it at all, we can't conclude anything, so just skip it.
95
- if (!cpuNodeForUrl) continue;
96
-
97
- // If we found it and it was in our `cpuNodes` set that means it finished before cutoffTimestamp, so it really is render-blocking.
98
- if (cpuNodes.includes(cpuNodeForUrl)) {
99
- renderBlockingCpuNodeIds.add(cpuNodeForUrl.id);
100
- continue;
101
- }
102
-
103
- // We couldn't find the evaluate script in the set of CPU nodes that ran before our paint, so
104
- // it must not have been necessary for the paint.
105
- definitelyNotRenderBlockingScriptUrls.add(url);
106
- }
107
-
108
- // The first layout, first paint, and first ParseHTML are almost always necessary for first paint,
109
- // so we always include those CPU nodes.
110
- const firstLayout = cpuNodes.find(node => node.didPerformLayout());
111
- if (firstLayout) renderBlockingCpuNodeIds.add(firstLayout.id);
112
- const firstPaint = cpuNodes.find(node => node.childEvents.some(e => e.name === 'Paint'));
113
- if (firstPaint) renderBlockingCpuNodeIds.add(firstPaint.id);
114
- const firstParse = cpuNodes.find(node => node.childEvents.some(e => e.name === 'ParseHTML'));
115
- if (firstParse) renderBlockingCpuNodeIds.add(firstParse.id);
116
-
117
- // If a CPU filter was passed in, we also want to include those extra nodes.
118
- if (additionalCpuNodesToTreatAsRenderBlocking) {
119
- cpuNodes
120
- .filter(additionalCpuNodesToTreatAsRenderBlocking)
121
- .forEach(node => renderBlockingCpuNodeIds.add(node.id));
122
- }
123
-
124
- return {
125
- definitelyNotRenderBlockingScriptUrls,
126
- renderBlockingCpuNodeIds,
127
- };
128
- }
129
-
130
- /**
131
- * This function computes the graph required for the first paint of interest.
132
- *
133
- * @template [T=unknown]
134
- * @param {Node} dependencyGraph
135
- * @param {FirstPaintBasedGraphOpts<T>} opts
136
- * @return {Node}
137
- */
138
- static getFirstPaintBasedGraph(
139
- dependencyGraph,
140
- {cutoffTimestamp, treatNodeAsRenderBlocking, additionalCpuNodesToTreatAsRenderBlocking}
141
- ) {
142
- const rbData = this.getRenderBlockingNodeData(dependencyGraph, {
143
- cutoffTimestamp,
144
- treatNodeAsRenderBlocking,
145
- additionalCpuNodesToTreatAsRenderBlocking,
146
- });
147
- const {definitelyNotRenderBlockingScriptUrls, renderBlockingCpuNodeIds} = rbData;
148
-
149
- return dependencyGraph.cloneWithRelationships(node => {
150
- if (node.type === BaseNode.TYPES.NETWORK) {
151
- // Exclude all nodes that ended after cutoffTimestamp (except for the main document which we always consider necessary)
152
- // endTime is negative if request does not finish, make sure startTime isn't after cutoffTimestamp in this case.
153
- const endedAfterPaint = node.endTime > cutoffTimestamp || node.startTime > cutoffTimestamp;
154
- if (endedAfterPaint && !node.isMainDocument()) return false;
155
-
156
- const url = node.record.url;
157
- // If the URL definitely wasn't render-blocking then we filter it out.
158
- if (definitelyNotRenderBlockingScriptUrls.has(url)) {
159
- return false;
160
- }
161
-
162
- // Lastly, build up the FCP graph of all nodes we consider render blocking
163
- return treatNodeAsRenderBlocking(node);
164
- } else {
165
- // If it's a CPU node, just check if it was blocking.
166
- return renderBlockingCpuNodeIds.has(node.id);
167
- }
168
- });
169
- }
170
-
171
- /**
172
- * @param {Node} dependencyGraph
173
- * @param {LH.Artifacts.ProcessedNavigation} processedNavigation
174
- * @return {Node}
175
- */
176
- static getOptimisticGraph(dependencyGraph, processedNavigation) {
177
- return this.getFirstPaintBasedGraph(dependencyGraph, {
178
- cutoffTimestamp: processedNavigation.timestamps.firstContentfulPaint,
179
- // In the optimistic graph we exclude resources that appeared to be render blocking but were
180
- // initiated by a script. While they typically have a very high importance and tend to have a
181
- // significant impact on the page's content, these resources don't technically block rendering.
182
- treatNodeAsRenderBlocking: node =>
183
- node.hasRenderBlockingPriority() && node.initiatorType !== 'script',
184
- });
185
- }
186
-
187
- /**
188
- * @param {Node} dependencyGraph
189
- * @param {LH.Artifacts.ProcessedNavigation} processedNavigation
190
- * @return {Node}
191
- */
192
- static getPessimisticGraph(dependencyGraph, processedNavigation) {
193
- return this.getFirstPaintBasedGraph(dependencyGraph, {
194
- cutoffTimestamp: processedNavigation.timestamps.firstContentfulPaint,
195
- treatNodeAsRenderBlocking: node => node.hasRenderBlockingPriority(),
196
- });
197
- }
198
- }
199
-
200
- export {FirstContentfulPaint};
@@ -1,6 +0,0 @@
1
- export type Node = import('../base-node.js').Node;
2
- /** @typedef {import('../base-node.js').Node} Node */
3
- export class FirstMeaningfulPaint extends Metric {
4
- }
5
- import { Metric } from '../metric.js';
6
- //# sourceMappingURL=first-meaningful-paint.d.ts.map
@@ -1,66 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2024 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import * as Lantern from '../types/lantern.js';
8
- import {Metric} from '../metric.js';
9
- // TODO(15841): don't use LighthouseError
10
- import {LighthouseError} from '../../lh-error.js';
11
- import {FirstContentfulPaint} from './first-contentful-paint.js';
12
-
13
- /** @typedef {import('../base-node.js').Node} Node */
14
-
15
- class FirstMeaningfulPaint extends Metric {
16
- /**
17
- * @return {Lantern.Simulation.MetricCoefficients}
18
- */
19
- static get COEFFICIENTS() {
20
- return {
21
- intercept: 0,
22
- optimistic: 0.5,
23
- pessimistic: 0.5,
24
- };
25
- }
26
-
27
- /**
28
- * @param {Node} dependencyGraph
29
- * @param {LH.Artifacts.ProcessedNavigation} processedNavigation
30
- * @return {Node}
31
- */
32
- static getOptimisticGraph(dependencyGraph, processedNavigation) {
33
- const fmp = processedNavigation.timestamps.firstMeaningfulPaint;
34
- if (!fmp) {
35
- throw new LighthouseError(LighthouseError.errors.NO_FMP);
36
- }
37
- return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {
38
- cutoffTimestamp: fmp,
39
- // See FirstContentfulPaint's getOptimisticGraph implementation for a longer description
40
- // of why we exclude script initiated resources here.
41
- treatNodeAsRenderBlocking: node =>
42
- node.hasRenderBlockingPriority() && node.initiatorType !== 'script',
43
- });
44
- }
45
-
46
- /**
47
- * @param {Node} dependencyGraph
48
- * @param {LH.Artifacts.ProcessedNavigation} processedNavigation
49
- * @return {Node}
50
- */
51
- static getPessimisticGraph(dependencyGraph, processedNavigation) {
52
- const fmp = processedNavigation.timestamps.firstMeaningfulPaint;
53
- if (!fmp) {
54
- throw new LighthouseError(LighthouseError.errors.NO_FMP);
55
- }
56
-
57
- return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {
58
- cutoffTimestamp: fmp,
59
- treatNodeAsRenderBlocking: node => node.hasRenderBlockingPriority(),
60
- // For pessimistic FMP we'll include *all* layout nodes
61
- additionalCpuNodesToTreatAsRenderBlocking: node => node.didPerformLayout(),
62
- });
63
- }
64
- }
65
-
66
- export {FirstMeaningfulPaint};
@@ -1,26 +0,0 @@
1
- export type Node = import('../base-node.js').Node;
2
- export class Interactive extends Metric {
3
- /**
4
- * @param {Node} dependencyGraph
5
- * @return {Node}
6
- */
7
- static getOptimisticGraph(dependencyGraph: Node): Node;
8
- /**
9
- * @param {Node} dependencyGraph
10
- * @return {Node}
11
- */
12
- static getPessimisticGraph(dependencyGraph: Node): Node;
13
- /**
14
- * @param {LH.Gatherer.Simulation.Result} simulationResult
15
- * @param {import('../metric.js').Extras} extras
16
- * @return {LH.Gatherer.Simulation.Result}
17
- */
18
- static getEstimateFromSimulation(simulationResult: LH.Gatherer.Simulation.Result, extras: import('../metric.js').Extras): LH.Gatherer.Simulation.Result;
19
- /**
20
- * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
21
- * @return {number}
22
- */
23
- static getLastLongTaskEndTime(nodeTimings: LH.Gatherer.Simulation.Result['nodeTimings'], duration?: number): number;
24
- }
25
- import { Metric } from '../metric.js';
26
- //# sourceMappingURL=interactive.d.ts.map
@@ -1,112 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2024 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import * as Lantern from '../types/lantern.js';
8
- import {Metric} from '../metric.js';
9
- import {BaseNode} from '../base-node.js';
10
- import {NetworkRequestTypes} from '../lantern.js';
11
-
12
- /** @typedef {import('../base-node.js').Node} Node */
13
-
14
- // Any CPU task of 20 ms or more will end up being a critical long task on mobile
15
- const CRITICAL_LONG_TASK_THRESHOLD = 20;
16
-
17
- class Interactive extends Metric {
18
- /**
19
- * @return {LH.Gatherer.Simulation.MetricCoefficients}
20
- */
21
- static get COEFFICIENTS() {
22
- return {
23
- intercept: 0,
24
- optimistic: 0.5,
25
- pessimistic: 0.5,
26
- };
27
- }
28
-
29
- /**
30
- * @param {Node} dependencyGraph
31
- * @return {Node}
32
- */
33
- static getOptimisticGraph(dependencyGraph) {
34
- // Adjust the critical long task threshold for microseconds
35
- const minimumCpuTaskDuration = CRITICAL_LONG_TASK_THRESHOLD * 1000;
36
-
37
- return dependencyGraph.cloneWithRelationships(node => {
38
- // Include everything that might be a long task
39
- if (node.type === BaseNode.TYPES.CPU) {
40
- return node.event.dur > minimumCpuTaskDuration;
41
- }
42
-
43
- // Include all scripts and high priority requests, exclude all images
44
- const isImage = node.record.resourceType === NetworkRequestTypes.Image;
45
- const isScript = node.record.resourceType === NetworkRequestTypes.Script;
46
- return (
47
- !isImage &&
48
- (isScript ||
49
- node.record.priority === 'High' ||
50
- node.record.priority === 'VeryHigh')
51
- );
52
- });
53
- }
54
-
55
- /**
56
- * @param {Node} dependencyGraph
57
- * @return {Node}
58
- */
59
- static getPessimisticGraph(dependencyGraph) {
60
- return dependencyGraph;
61
- }
62
-
63
- /**
64
- * @param {LH.Gatherer.Simulation.Result} simulationResult
65
- * @param {import('../metric.js').Extras} extras
66
- * @return {LH.Gatherer.Simulation.Result}
67
- */
68
- static getEstimateFromSimulation(simulationResult, extras) {
69
- if (!extras.fmpResult) throw new Error('missing fmpResult');
70
-
71
- const lastTaskAt = Interactive.getLastLongTaskEndTime(simulationResult.nodeTimings);
72
- const minimumTime = extras.optimistic
73
- ? extras.fmpResult.optimisticEstimate.timeInMs
74
- : extras.fmpResult.pessimisticEstimate.timeInMs;
75
- return {
76
- timeInMs: Math.max(minimumTime, lastTaskAt),
77
- nodeTimings: simulationResult.nodeTimings,
78
- };
79
- }
80
-
81
- /**
82
- * @param {Lantern.Simulation.MetricComputationDataInput} data
83
- * @param {Omit<import('../metric.js').Extras, 'optimistic'>=} extras
84
- * @return {Promise<LH.Artifacts.LanternMetric>}
85
- */
86
- static async compute(data, extras) {
87
- const fmpResult = extras?.fmpResult;
88
- if (!fmpResult) {
89
- throw new Error('FMP is required to calculate the Interactive metric');
90
- }
91
-
92
- const metricResult = await super.compute(data, extras);
93
- metricResult.timing = Math.max(metricResult.timing, fmpResult.timing);
94
- return metricResult;
95
- }
96
-
97
- /**
98
- * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
99
- * @return {number}
100
- */
101
- static getLastLongTaskEndTime(nodeTimings, duration = 50) {
102
- return Array.from(nodeTimings.entries())
103
- .filter(([node, timing]) => {
104
- if (node.type !== BaseNode.TYPES.CPU) return false;
105
- return timing.duration > duration;
106
- })
107
- .map(([_, timing]) => timing.endTime)
108
- .reduce((max, x) => Math.max(max || 0, x || 0), 0);
109
- }
110
- }
111
-
112
- export {Interactive};
@@ -1,19 +0,0 @@
1
- export type Node = import('../base-node.js').Node;
2
- /** @typedef {import('../base-node.js').Node} Node */
3
- export class LargestContentfulPaint extends Metric {
4
- /**
5
- * Low priority image nodes are usually offscreen and very unlikely to be the
6
- * resource that is required for LCP. Our LCP graphs include everything except for these images.
7
- *
8
- * @param {Node} node
9
- * @return {boolean}
10
- */
11
- static isNotLowPriorityImageNode(node: Node): boolean;
12
- /**
13
- * @param {LH.Gatherer.Simulation.Result} simulationResult
14
- * @return {LH.Gatherer.Simulation.Result}
15
- */
16
- static getEstimateFromSimulation(simulationResult: LH.Gatherer.Simulation.Result): LH.Gatherer.Simulation.Result;
17
- }
18
- import { Metric } from '../metric.js';
19
- //# sourceMappingURL=largest-contentful-paint.d.ts.map
@@ -1,108 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2024 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import * as Lantern from '../types/lantern.js';
8
- import {Metric} from '../metric.js';
9
- import {LighthouseError} from '../../../lib/lh-error.js';
10
- import {FirstContentfulPaint} from './first-contentful-paint.js';
11
-
12
- /** @typedef {import('../base-node.js').Node} Node */
13
-
14
- class LargestContentfulPaint extends Metric {
15
- /**
16
- * @return {LH.Gatherer.Simulation.MetricCoefficients}
17
- */
18
- static get COEFFICIENTS() {
19
- return {
20
- intercept: 0,
21
- optimistic: 0.5,
22
- pessimistic: 0.5,
23
- };
24
- }
25
-
26
- /**
27
- * Low priority image nodes are usually offscreen and very unlikely to be the
28
- * resource that is required for LCP. Our LCP graphs include everything except for these images.
29
- *
30
- * @param {Node} node
31
- * @return {boolean}
32
- */
33
- static isNotLowPriorityImageNode(node) {
34
- if (node.type !== 'network') return true;
35
- const isImage = node.record.resourceType === 'Image';
36
- const isLowPriority = node.record.priority === 'Low' || node.record.priority === 'VeryLow';
37
- return !isImage || !isLowPriority;
38
- }
39
-
40
- /**
41
- * @param {Node} dependencyGraph
42
- * @param {LH.Artifacts.ProcessedNavigation} processedNavigation
43
- * @return {Node}
44
- */
45
- static getOptimisticGraph(dependencyGraph, processedNavigation) {
46
- const lcp = processedNavigation.timestamps.largestContentfulPaint;
47
- if (!lcp) {
48
- throw new LighthouseError(LighthouseError.errors.NO_LCP);
49
- }
50
-
51
- return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {
52
- cutoffTimestamp: lcp,
53
- treatNodeAsRenderBlocking: LargestContentfulPaint.isNotLowPriorityImageNode,
54
- });
55
- }
56
-
57
- /**
58
- * @param {Node} dependencyGraph
59
- * @param {LH.Artifacts.ProcessedNavigation} processedNavigation
60
- * @return {Node}
61
- */
62
- static getPessimisticGraph(dependencyGraph, processedNavigation) {
63
- const lcp = processedNavigation.timestamps.largestContentfulPaint;
64
- if (!lcp) {
65
- throw new LighthouseError(LighthouseError.errors.NO_LCP);
66
- }
67
-
68
- return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {
69
- cutoffTimestamp: lcp,
70
- treatNodeAsRenderBlocking: _ => true,
71
- // For pessimistic LCP we'll include *all* layout nodes
72
- additionalCpuNodesToTreatAsRenderBlocking: node => node.didPerformLayout(),
73
- });
74
- }
75
-
76
- /**
77
- * @param {LH.Gatherer.Simulation.Result} simulationResult
78
- * @return {LH.Gatherer.Simulation.Result}
79
- */
80
- static getEstimateFromSimulation(simulationResult) {
81
- const nodeTimesNotOffscreenImages = Array.from(simulationResult.nodeTimings.entries())
82
- .filter(entry => LargestContentfulPaint.isNotLowPriorityImageNode(entry[0]))
83
- .map(entry => entry[1].endTime);
84
-
85
- return {
86
- timeInMs: Math.max(...nodeTimesNotOffscreenImages),
87
- nodeTimings: simulationResult.nodeTimings,
88
- };
89
- }
90
-
91
- /**
92
- * @param {Lantern.Simulation.MetricComputationDataInput} data
93
- * @param {Omit<import('../metric.js').Extras, 'optimistic'>=} extras
94
- * @return {Promise<LH.Artifacts.LanternMetric>}
95
- */
96
- static async compute(data, extras) {
97
- const fcpResult = extras?.fcpResult;
98
- if (!fcpResult) {
99
- throw new Error('FCP is required to calculate the LCP metric');
100
- }
101
-
102
- const metricResult = await super.compute(data, extras);
103
- metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);
104
- return metricResult;
105
- }
106
- }
107
-
108
- export {LargestContentfulPaint};
@@ -1,30 +0,0 @@
1
- export type Node = import('../base-node.js').Node;
2
- /** @typedef {import('../base-node.js').Node} Node */
3
- export class MaxPotentialFID extends Metric {
4
- /**
5
- * @param {Node} dependencyGraph
6
- * @return {Node}
7
- */
8
- static getOptimisticGraph(dependencyGraph: Node): Node;
9
- /**
10
- * @param {Node} dependencyGraph
11
- * @return {Node}
12
- */
13
- static getPessimisticGraph(dependencyGraph: Node): Node;
14
- /**
15
- * @param {LH.Gatherer.Simulation.Result} simulation
16
- * @param {import('../metric.js').Extras} extras
17
- * @return {LH.Gatherer.Simulation.Result}
18
- */
19
- static getEstimateFromSimulation(simulation: LH.Gatherer.Simulation.Result, extras: import('../metric.js').Extras): LH.Gatherer.Simulation.Result;
20
- /**
21
- * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
22
- * @param {number} fcpTimeInMs
23
- * @return {Array<{duration: number}>}
24
- */
25
- static getTimingsAfterFCP(nodeTimings: LH.Gatherer.Simulation.Result['nodeTimings'], fcpTimeInMs: number): Array<{
26
- duration: number;
27
- }>;
28
- }
29
- import { Metric } from '../metric.js';
30
- //# sourceMappingURL=max-potential-fid.d.ts.map
@@ -1,92 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2024 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import * as Lantern from '../types/lantern.js';
8
- import {Metric} from '../metric.js';
9
- import {BaseNode} from '../base-node.js';
10
-
11
- /** @typedef {import('../base-node.js').Node} Node */
12
-
13
- class MaxPotentialFID extends Metric {
14
- /**
15
- * @return {LH.Gatherer.Simulation.MetricCoefficients}
16
- */
17
- static get COEFFICIENTS() {
18
- return {
19
- intercept: 0,
20
- optimistic: 0.5,
21
- pessimistic: 0.5,
22
- };
23
- }
24
-
25
- /**
26
- * @param {Node} dependencyGraph
27
- * @return {Node}
28
- */
29
- static getOptimisticGraph(dependencyGraph) {
30
- return dependencyGraph;
31
- }
32
-
33
- /**
34
- * @param {Node} dependencyGraph
35
- * @return {Node}
36
- */
37
- static getPessimisticGraph(dependencyGraph) {
38
- return dependencyGraph;
39
- }
40
-
41
- /**
42
- * @param {LH.Gatherer.Simulation.Result} simulation
43
- * @param {import('../metric.js').Extras} extras
44
- * @return {LH.Gatherer.Simulation.Result}
45
- */
46
- static getEstimateFromSimulation(simulation, extras) {
47
- if (!extras.fcpResult) throw new Error('missing fcpResult');
48
-
49
- // Intentionally use the opposite FCP estimate, a more pessimistic FCP means that more tasks
50
- // are excluded from the FID computation, so a higher FCP means lower FID for same work.
51
- const fcpTimeInMs = extras.optimistic
52
- ? extras.fcpResult.pessimisticEstimate.timeInMs
53
- : extras.fcpResult.optimisticEstimate.timeInMs;
54
-
55
- const timings = MaxPotentialFID.getTimingsAfterFCP(
56
- simulation.nodeTimings,
57
- fcpTimeInMs
58
- );
59
-
60
- return {
61
- timeInMs: Math.max(...timings.map(timing => timing.duration), 16),
62
- nodeTimings: simulation.nodeTimings,
63
- };
64
- }
65
-
66
- /**
67
- * @param {Lantern.Simulation.MetricComputationDataInput} data
68
- * @param {Omit<import('../metric.js').Extras, 'optimistic'>=} extras
69
- * @return {Promise<LH.Artifacts.LanternMetric>}
70
- */
71
- static compute(data, extras) {
72
- const fcpResult = extras?.fcpResult;
73
- if (!fcpResult) {
74
- throw new Error('FCP is required to calculate the Max Potential FID metric');
75
- }
76
-
77
- return super.compute(data, extras);
78
- }
79
-
80
- /**
81
- * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
82
- * @param {number} fcpTimeInMs
83
- * @return {Array<{duration: number}>}
84
- */
85
- static getTimingsAfterFCP(nodeTimings, fcpTimeInMs) {
86
- return Array.from(nodeTimings.entries())
87
- .filter(([node, timing]) => node.type === BaseNode.TYPES.CPU && timing.endTime > fcpTimeInMs)
88
- .map(([_, timing]) => timing);
89
- }
90
- }
91
-
92
- export {MaxPotentialFID};