lighthouse 10.3.0-dev.20230704 → 10.3.0-dev.20230706

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 (43) hide show
  1. package/core/audits/accessibility/empty-heading.d.ts +10 -0
  2. package/core/audits/accessibility/empty-heading.js +45 -0
  3. package/core/audits/accessibility/identical-links-same-purpose.d.ts +10 -0
  4. package/core/audits/accessibility/identical-links-same-purpose.js +45 -0
  5. package/core/audits/accessibility/landmark-one-main.d.ts +10 -0
  6. package/core/audits/accessibility/landmark-one-main.js +44 -0
  7. package/core/audits/accessibility/target-size.d.ts +10 -0
  8. package/core/audits/accessibility/target-size.js +45 -0
  9. package/core/audits/audit.d.ts +6 -0
  10. package/core/audits/audit.js +12 -0
  11. package/core/audits/byte-efficiency/byte-efficiency-audit.d.ts +22 -6
  12. package/core/audits/byte-efficiency/byte-efficiency-audit.js +97 -25
  13. package/core/audits/prioritize-lcp-image.js +2 -1
  14. package/core/audits/redirects.js +4 -0
  15. package/core/audits/unsized-images.js +3 -0
  16. package/core/computed/js-bundles.js +1 -1
  17. package/core/computed/metrics/tbt-utils.d.ts +26 -0
  18. package/core/computed/metrics/tbt-utils.js +48 -28
  19. package/core/computed/metrics/total-blocking-time.js +1 -1
  20. package/core/computed/tbt-impact-tasks.d.ts +54 -0
  21. package/core/computed/tbt-impact-tasks.js +221 -0
  22. package/core/config/default-config.js +9 -0
  23. package/core/config/filters.d.ts +9 -9
  24. package/core/config/filters.js +7 -7
  25. package/core/config/validation.js +12 -0
  26. package/core/gather/gatherers/accessibility.js +4 -1
  27. package/core/gather/gatherers/seo/font-size.d.ts +0 -1
  28. package/core/gather/gatherers/seo/font-size.js +0 -1
  29. package/core/gather/gatherers/source-maps.js +3 -2
  30. package/core/lib/cdt/SDK.d.ts +1 -1
  31. package/core/lib/cdt/SDK.js +2 -2
  32. package/core/lib/dependency-graph/simulator/simulator.js +3 -1
  33. package/core/lib/navigation-error.d.ts +2 -2
  34. package/core/lib/navigation-error.js +1 -1
  35. package/dist/report/bundle.esm.js +1 -0
  36. package/dist/report/flow.js +1 -1
  37. package/dist/report/standalone.js +1 -1
  38. package/package.json +3 -3
  39. package/report/renderer/category-renderer.js +1 -0
  40. package/shared/localization/locales/en-US.json +36 -0
  41. package/shared/localization/locales/en-XL.json +36 -0
  42. package/tsconfig.json +1 -1
  43. package/types/artifacts.d.ts +9 -2
@@ -0,0 +1,10 @@
1
+ export default EmptyHeading;
2
+ declare class EmptyHeading extends AxeAudit {
3
+ }
4
+ export namespace UIStrings {
5
+ const title: string;
6
+ const failureTitle: string;
7
+ const description: string;
8
+ }
9
+ import AxeAudit from './axe-audit.js';
10
+ //# sourceMappingURL=empty-heading.d.ts.map
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license Copyright 2023 The Lighthouse Authors. All Rights Reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
+ */
6
+
7
+ /**
8
+ * @fileoverview Ensures that headings are not empty.
9
+ * See base class in axe-audit.js for audit() implementation.
10
+ */
11
+
12
+ import AxeAudit from './axe-audit.js';
13
+ import * as i18n from '../../lib/i18n/i18n.js';
14
+
15
+ const UIStrings = {
16
+ /** Title of an accesibility audit that checks if all heading elements have content. This title is descriptive of the successful state and is shown to users when no user action is required. */
17
+ title: 'All heading elements contain content.',
18
+ /** Title of an accesibility audit that checks if all heading elements have content. This title is descriptive of the failing state and is shown to users when there is a failure that needs to be addressed. */
19
+ failureTitle: 'Heading elements do not contain content.',
20
+ /** Description of a Lighthouse audit that tells the user *why* they should try to pass. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
21
+ description: 'A heading with no content or inaccessible text prevent screen reader users from ' +
22
+ 'accessing information on the page\'s structure. ' +
23
+ '[Learn more about headings](https://dequeuniversity.com/rules/axe/4.7/empty-heading).',
24
+ };
25
+
26
+ const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
27
+
28
+ class EmptyHeading extends AxeAudit {
29
+ /**
30
+ * @return {LH.Audit.Meta}
31
+ */
32
+ static get meta() {
33
+ return {
34
+ id: 'empty-heading',
35
+ title: str_(UIStrings.title),
36
+ failureTitle: str_(UIStrings.failureTitle),
37
+ description: str_(UIStrings.description),
38
+ scoreDisplayMode: AxeAudit.SCORING_MODES.INFORMATIVE,
39
+ requiredArtifacts: ['Accessibility'],
40
+ };
41
+ }
42
+ }
43
+
44
+ export default EmptyHeading;
45
+ export {UIStrings};
@@ -0,0 +1,10 @@
1
+ export default IdenticalLinksSamePurpose;
2
+ declare class IdenticalLinksSamePurpose extends AxeAudit {
3
+ }
4
+ export namespace UIStrings {
5
+ const title: string;
6
+ const failureTitle: string;
7
+ const description: string;
8
+ }
9
+ import AxeAudit from './axe-audit.js';
10
+ //# sourceMappingURL=identical-links-same-purpose.d.ts.map
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license Copyright 2023 The Lighthouse Authors. All Rights Reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
+ */
6
+
7
+ /**
8
+ * @fileoverview Ensures that identical links have the same purpose.
9
+ * See base class in axe-audit.js for audit() implementation.
10
+ */
11
+
12
+ import AxeAudit from './axe-audit.js';
13
+ import * as i18n from '../../lib/i18n/i18n.js';
14
+
15
+ const UIStrings = {
16
+ /** Title of an accesibility audit that checks if identical links have the same purpose. This title is descriptive of the successful state and is shown to users when no user action is required. */
17
+ title: 'Identical links have the same purpose.',
18
+ /** Title of an accesibility audit that checks if identical links have the same purpose. This title is descriptive of the failing state and is shown to users when there is a failure that needs to be addressed. */
19
+ failureTitle: 'Identical links do not have the same purpose.',
20
+ /** Description of a Lighthouse audit that tells the user *why* they should try to pass. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
21
+ description: 'Links with the same destination should have the same description, to help users ' +
22
+ 'understand the link\'s purpose and decide whether to follow it. ' +
23
+ '[Learn more about identical links](https://dequeuniversity.com/rules/axe/4.7/identical-links-same-purpose).',
24
+ };
25
+
26
+ const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
27
+
28
+ class IdenticalLinksSamePurpose extends AxeAudit {
29
+ /**
30
+ * @return {LH.Audit.Meta}
31
+ */
32
+ static get meta() {
33
+ return {
34
+ id: 'identical-links-same-purpose',
35
+ title: str_(UIStrings.title),
36
+ failureTitle: str_(UIStrings.failureTitle),
37
+ description: str_(UIStrings.description),
38
+ scoreDisplayMode: AxeAudit.SCORING_MODES.INFORMATIVE,
39
+ requiredArtifacts: ['Accessibility'],
40
+ };
41
+ }
42
+ }
43
+
44
+ export default IdenticalLinksSamePurpose;
45
+ export {UIStrings};
@@ -0,0 +1,10 @@
1
+ export default LandmarkOneMain;
2
+ declare class LandmarkOneMain extends AxeAudit {
3
+ }
4
+ export namespace UIStrings {
5
+ const title: string;
6
+ const failureTitle: string;
7
+ const description: string;
8
+ }
9
+ import AxeAudit from './axe-audit.js';
10
+ //# sourceMappingURL=landmark-one-main.d.ts.map
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @license Copyright 2023 The Lighthouse Authors. All Rights Reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
+ */
6
+
7
+ /**
8
+ * @fileoverview Ensures that the document has a main landmark.
9
+ * See base class in axe-audit.js for audit() implementation.
10
+ */
11
+
12
+ import AxeAudit from './axe-audit.js';
13
+ import * as i18n from '../../lib/i18n/i18n.js';
14
+
15
+ const UIStrings = {
16
+ /** Title of an accesibility audit that checks if the document has a main landmark. This title is descriptive of the successful state and is shown to users when no user action is required. */
17
+ title: 'Document has a main landmark.',
18
+ /** Title of an accesibility audit that checks if the document has a main landmark. This title is descriptive of the failing state and is shown to users when there is a failure that needs to be addressed. */
19
+ failureTitle: 'Document does not have a main landmark.',
20
+ /** Description of a Lighthouse audit that tells the user *why* they should try to pass. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
21
+ description: 'One main landmark helps screen reader users navigate a web page. ' +
22
+ '[Learn more about landmarks](https://dequeuniversity.com/rules/axe/4.7/landmark-one-main).',
23
+ };
24
+
25
+ const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
26
+
27
+ class LandmarkOneMain extends AxeAudit {
28
+ /**
29
+ * @return {LH.Audit.Meta}
30
+ */
31
+ static get meta() {
32
+ return {
33
+ id: 'landmark-one-main',
34
+ title: str_(UIStrings.title),
35
+ failureTitle: str_(UIStrings.failureTitle),
36
+ description: str_(UIStrings.description),
37
+ scoreDisplayMode: AxeAudit.SCORING_MODES.INFORMATIVE,
38
+ requiredArtifacts: ['Accessibility'],
39
+ };
40
+ }
41
+ }
42
+
43
+ export default LandmarkOneMain;
44
+ export {UIStrings};
@@ -0,0 +1,10 @@
1
+ export default TargetSize;
2
+ declare class TargetSize extends AxeAudit {
3
+ }
4
+ export namespace UIStrings {
5
+ const title: string;
6
+ const failureTitle: string;
7
+ const description: string;
8
+ }
9
+ import AxeAudit from './axe-audit.js';
10
+ //# sourceMappingURL=target-size.d.ts.map
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license Copyright 2023 The Lighthouse Authors. All Rights Reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
+ */
6
+
7
+ /**
8
+ * @fileoverview Ensures that touch targets have sufficient size and spacing.
9
+ * See base class in axe-audit.js for audit() implementation.
10
+ */
11
+
12
+ import AxeAudit from './axe-audit.js';
13
+ import * as i18n from '../../lib/i18n/i18n.js';
14
+
15
+ const UIStrings = {
16
+ /** Title of an accesibility audit that checks if all touch targets have sufficient size and spacing. This title is descriptive of the successful state and is shown to users when no user action is required. */
17
+ title: 'Touch targets have sufficient size and spacing.',
18
+ /** Title of an accesibility audit that checks if all touch targets have sufficient size and spacing. This title is descriptive of the failing state and is shown to users when there is a failure that needs to be addressed. */
19
+ failureTitle: 'Touch targets do not have sufficient size or spacing.',
20
+ /** Description of a Lighthouse audit that tells the user *why* they should try to pass. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
21
+ description: 'Touch targets with sufficient size and spacing help users who may have ' +
22
+ 'difficulty targeting small controls activate the targets. ' +
23
+ '[Learn more about touch targets](https://dequeuniversity.com/rules/axe/4.7/target-size).',
24
+ };
25
+
26
+ const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
27
+
28
+ class TargetSize extends AxeAudit {
29
+ /**
30
+ * @return {LH.Audit.Meta}
31
+ */
32
+ static get meta() {
33
+ return {
34
+ id: 'target-size',
35
+ title: str_(UIStrings.title),
36
+ failureTitle: str_(UIStrings.failureTitle),
37
+ description: str_(UIStrings.description),
38
+ scoreDisplayMode: AxeAudit.SCORING_MODES.INFORMATIVE,
39
+ requiredArtifacts: ['Accessibility'],
40
+ };
41
+ }
42
+ }
43
+
44
+ export default TargetSize;
45
+ export {UIStrings};
@@ -159,6 +159,12 @@ export class Audit {
159
159
  * @return {LH.RawIcu<LH.Audit.Result>}
160
160
  */
161
161
  static generateAuditResult(audit: typeof Audit, product: LH.Audit.Product): LH.RawIcu<LH.Audit.Result>;
162
+ /**
163
+ * @param {LH.Artifacts} artifacts
164
+ * @param {LH.Audit.Context} context
165
+ * @returns {LH.Artifacts.MetricComputationDataInput}
166
+ */
167
+ static makeMetricComputationDataInput(artifacts: LH.Artifacts, context: LH.Audit.Context): LH.Artifacts.MetricComputationDataInput;
162
168
  }
163
169
  import * as LH from '../../types/lh.js';
164
170
  //# sourceMappingURL=audit.d.ts.map
@@ -415,6 +415,18 @@ class Audit {
415
415
  details: product.details,
416
416
  };
417
417
  }
418
+
419
+ /**
420
+ * @param {LH.Artifacts} artifacts
421
+ * @param {LH.Audit.Context} context
422
+ * @returns {LH.Artifacts.MetricComputationDataInput}
423
+ */
424
+ static makeMetricComputationDataInput(artifacts, context) {
425
+ const trace = artifacts.traces[Audit.DEFAULT_PASS];
426
+ const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
427
+ const gatherContext = artifacts.GatherContext;
428
+ return {trace, devtoolsLog, gatherContext, settings: context.settings, URL: artifacts.URL};
429
+ }
418
430
  }
419
431
 
420
432
  export {Audit};
@@ -49,6 +49,23 @@ export class ByteEfficiencyAudit extends Audit {
49
49
  * @return {Promise<LH.Audit.Product>}
50
50
  */
51
51
  static audit(artifacts: LH.Artifacts, context: LH.Audit.Context): Promise<LH.Audit.Product>;
52
+ /**
53
+ * Computes the estimated effect of all the byte savings on the provided graph.
54
+ *
55
+ * @param {Array<LH.Audit.ByteEfficiencyItem>} results The array of byte savings results per resource
56
+ * @param {Node} graph
57
+ * @param {Simulator} simulator
58
+ * @param {{label?: string, providedWastedBytesByUrl?: Map<string, number>}=} options
59
+ * @return {{savings: number, simulationBeforeChanges: LH.Gatherer.Simulation.Result, simulationAfterChanges: LH.Gatherer.Simulation.Result}}
60
+ */
61
+ static computeWasteWithGraph(results: Array<LH.Audit.ByteEfficiencyItem>, graph: Node, simulator: Simulator, options?: {
62
+ label?: string;
63
+ providedWastedBytesByUrl?: Map<string, number>;
64
+ } | undefined): {
65
+ savings: number;
66
+ simulationBeforeChanges: LH.Gatherer.Simulation.Result;
67
+ simulationAfterChanges: LH.Gatherer.Simulation.Result;
68
+ };
52
69
  /**
53
70
  * Computes the estimated effect of all the byte savings on the maximum of the following:
54
71
  *
@@ -58,22 +75,21 @@ export class ByteEfficiencyAudit extends Audit {
58
75
  * @param {Array<LH.Audit.ByteEfficiencyItem>} results The array of byte savings results per resource
59
76
  * @param {Node} graph
60
77
  * @param {Simulator} simulator
61
- * @param {{includeLoad?: boolean, label?: string, providedWastedBytesByUrl?: Map<string, number>}=} options
78
+ * @param {{includeLoad?: boolean, providedWastedBytesByUrl?: Map<string, number>}=} options
62
79
  * @return {number}
63
80
  */
64
81
  static computeWasteWithTTIGraph(results: Array<LH.Audit.ByteEfficiencyItem>, graph: Node, simulator: Simulator, options?: {
65
82
  includeLoad?: boolean;
66
- label?: string;
67
83
  providedWastedBytesByUrl?: Map<string, number>;
68
84
  } | undefined): number;
69
85
  /**
70
86
  * @param {ByteEfficiencyProduct} result
71
- * @param {Node|null} graph
72
87
  * @param {Simulator} simulator
73
- * @param {LH.Artifacts['GatherContext']} gatherContext
74
- * @return {LH.Audit.Product}
88
+ * @param {LH.Artifacts.MetricComputationDataInput} metricComputationInput
89
+ * @param {LH.Audit.Context} context
90
+ * @return {Promise<LH.Audit.Product>}
75
91
  */
76
- static createAuditProduct(result: ByteEfficiencyProduct, graph: Node | null, simulator: Simulator, gatherContext: LH.Artifacts['GatherContext']): LH.Audit.Product;
92
+ static createAuditProduct(result: ByteEfficiencyProduct, simulator: Simulator, metricComputationInput: LH.Artifacts.MetricComputationDataInput, context: LH.Audit.Context): Promise<LH.Audit.Product>;
77
93
  /**
78
94
  * @param {LH.Artifacts} artifacts
79
95
  * @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
@@ -10,6 +10,9 @@ import * as i18n from '../../lib/i18n/i18n.js';
10
10
  import {NetworkRecords} from '../../computed/network-records.js';
11
11
  import {LoadSimulator} from '../../computed/load-simulator.js';
12
12
  import {PageDependencyGraph} from '../../computed/page-dependency-graph.js';
13
+ import {LanternLargestContentfulPaint} from '../../computed/metrics/lantern-largest-contentful-paint.js';
14
+ import {LanternFirstContentfulPaint} from '../../computed/metrics/lantern-first-contentful-paint.js';
15
+ import {LCPImageRecord} from '../../computed/lcp-image-record.js';
13
16
 
14
17
  const str_ = i18n.createIcuMessageFn(import.meta.url, {});
15
18
 
@@ -104,9 +107,7 @@ class ByteEfficiencyAudit extends Audit {
104
107
  */
105
108
  static async audit(artifacts, context) {
106
109
  const gatherContext = artifacts.GatherContext;
107
- const trace = artifacts.traces[Audit.DEFAULT_PASS];
108
110
  const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
109
- const URL = artifacts.URL;
110
111
  const settings = context?.settings || {};
111
112
  const simulatorOptions = {
112
113
  devtoolsLog,
@@ -125,34 +126,29 @@ class ByteEfficiencyAudit extends Audit {
125
126
  };
126
127
  }
127
128
 
128
- const [result, graph, simulator] = await Promise.all([
129
+ const metricComputationInput = Audit.makeMetricComputationDataInput(artifacts, context);
130
+
131
+ const [result, simulator] = await Promise.all([
129
132
  this.audit_(artifacts, networkRecords, context),
130
- // Page dependency graph is only used in navigation mode.
131
- gatherContext.gatherMode === 'navigation' ?
132
- PageDependencyGraph.request({trace, devtoolsLog, URL}, context) :
133
- null,
134
133
  LoadSimulator.request(simulatorOptions, context),
135
134
  ]);
136
135
 
137
- return this.createAuditProduct(result, graph, simulator, gatherContext);
136
+ return this.createAuditProduct(result, simulator, metricComputationInput, context);
138
137
  }
139
138
 
140
139
  /**
141
- * Computes the estimated effect of all the byte savings on the maximum of the following:
142
- *
143
- * - end time of the last long task in the provided graph
144
- * - (if includeLoad is true or not provided) end time of the last node in the graph
140
+ * Computes the estimated effect of all the byte savings on the provided graph.
145
141
  *
146
142
  * @param {Array<LH.Audit.ByteEfficiencyItem>} results The array of byte savings results per resource
147
143
  * @param {Node} graph
148
144
  * @param {Simulator} simulator
149
- * @param {{includeLoad?: boolean, label?: string, providedWastedBytesByUrl?: Map<string, number>}=} options
150
- * @return {number}
145
+ * @param {{label?: string, providedWastedBytesByUrl?: Map<string, number>}=} options
146
+ * @return {{savings: number, simulationBeforeChanges: LH.Gatherer.Simulation.Result, simulationAfterChanges: LH.Gatherer.Simulation.Result}}
151
147
  */
152
- static computeWasteWithTTIGraph(results, graph, simulator, options) {
153
- options = Object.assign({includeLoad: true, label: this.meta.id}, options);
154
- const beforeLabel = `${options.label}-before`;
155
- const afterLabel = `${options.label}-after`;
148
+ static computeWasteWithGraph(results, graph, simulator, options) {
149
+ options = Object.assign({label: ''}, options);
150
+ const beforeLabel = `${this.meta.id}-${options.label}-before`;
151
+ const afterLabel = `${this.meta.id}-${options.label}-after`;
156
152
 
157
153
  const simulationBeforeChanges = simulator.simulate(graph, {label: beforeLabel});
158
154
 
@@ -187,7 +183,36 @@ class ByteEfficiencyAudit extends Audit {
187
183
  node.record.transferSize = originalTransferSize;
188
184
  });
189
185
 
190
- const savingsOnOverallLoad = simulationBeforeChanges.timeInMs - simulationAfterChanges.timeInMs;
186
+ const savings = simulationBeforeChanges.timeInMs - simulationAfterChanges.timeInMs;
187
+
188
+ return {
189
+ // Round waste to nearest 10ms
190
+ savings: Math.round(Math.max(savings, 0) / 10) * 10,
191
+ simulationBeforeChanges,
192
+ simulationAfterChanges,
193
+ };
194
+ }
195
+
196
+ /**
197
+ * Computes the estimated effect of all the byte savings on the maximum of the following:
198
+ *
199
+ * - end time of the last long task in the provided graph
200
+ * - (if includeLoad is true or not provided) end time of the last node in the graph
201
+ *
202
+ * @param {Array<LH.Audit.ByteEfficiencyItem>} results The array of byte savings results per resource
203
+ * @param {Node} graph
204
+ * @param {Simulator} simulator
205
+ * @param {{includeLoad?: boolean, providedWastedBytesByUrl?: Map<string, number>}=} options
206
+ * @return {number}
207
+ */
208
+ static computeWasteWithTTIGraph(results, graph, simulator, options) {
209
+ options = Object.assign({includeLoad: true}, options);
210
+ const {savings: savingsOnOverallLoad, simulationBeforeChanges, simulationAfterChanges} =
211
+ this.computeWasteWithGraph(results, graph, simulator, {
212
+ ...options,
213
+ label: 'overallLoad',
214
+ });
215
+
191
216
  const savingsOnTTI =
192
217
  LanternInteractive.getLastLongTaskEndTime(simulationBeforeChanges.nodeTimings) -
193
218
  LanternInteractive.getLastLongTaskEndTime(simulationAfterChanges.nodeTimings);
@@ -201,24 +226,63 @@ class ByteEfficiencyAudit extends Audit {
201
226
 
202
227
  /**
203
228
  * @param {ByteEfficiencyProduct} result
204
- * @param {Node|null} graph
205
229
  * @param {Simulator} simulator
206
- * @param {LH.Artifacts['GatherContext']} gatherContext
207
- * @return {LH.Audit.Product}
230
+ * @param {LH.Artifacts.MetricComputationDataInput} metricComputationInput
231
+ * @param {LH.Audit.Context} context
232
+ * @return {Promise<LH.Audit.Product>}
208
233
  */
209
- static createAuditProduct(result, graph, simulator, gatherContext) {
234
+ static async createAuditProduct(result, simulator, metricComputationInput, context) {
210
235
  const results = result.items.sort((itemA, itemB) => itemB.wastedBytes - itemA.wastedBytes);
211
236
 
212
237
  const wastedBytes = results.reduce((sum, item) => sum + item.wastedBytes, 0);
213
238
 
239
+ /** @type {LH.Audit.MetricSavings} */
240
+ const metricSavings = {
241
+ FCP: 0,
242
+ LCP: 0,
243
+ };
244
+
214
245
  // `wastedMs` may be negative, if making the opportunity change could be detrimental.
215
246
  // This is useful information in the LHR and should be preserved.
216
247
  let wastedMs;
217
- if (gatherContext.gatherMode === 'navigation') {
218
- if (!graph) throw Error('Page dependency graph should always be computed in navigation mode');
248
+ if (metricComputationInput.gatherContext.gatherMode === 'navigation') {
249
+ const graph = await PageDependencyGraph.request(metricComputationInput, context);
250
+ const {
251
+ pessimisticGraph: pessimisticFCPGraph,
252
+ } = await LanternFirstContentfulPaint.request(metricComputationInput, context);
253
+ const {
254
+ pessimisticGraph: pessimisticLCPGraph,
255
+ } = await LanternLargestContentfulPaint.request(metricComputationInput, context);
256
+
219
257
  wastedMs = this.computeWasteWithTTIGraph(results, graph, simulator, {
220
258
  providedWastedBytesByUrl: result.wastedBytesByUrl,
221
259
  });
260
+
261
+ const {savings: fcpSavings} = this.computeWasteWithGraph(
262
+ results,
263
+ pessimisticFCPGraph,
264
+ simulator,
265
+ {providedWastedBytesByUrl: result.wastedBytesByUrl, label: 'fcp'}
266
+ );
267
+ const {savings: lcpGraphSavings} = this.computeWasteWithGraph(
268
+ results,
269
+ pessimisticLCPGraph,
270
+ simulator,
271
+ {providedWastedBytesByUrl: result.wastedBytesByUrl, label: 'lcp'}
272
+ );
273
+
274
+ // The LCP graph can underestimate the LCP savings if there is potential savings on the LCP record itself.
275
+ let lcpRecordSavings = 0;
276
+ const lcpRecord = await LCPImageRecord.request(metricComputationInput, context);
277
+ if (lcpRecord) {
278
+ const lcpResult = results.find(result => result.url === lcpRecord.url);
279
+ if (lcpResult) {
280
+ lcpRecordSavings = simulator.computeWastedMsFromWastedBytes(lcpResult.wastedBytes);
281
+ }
282
+ }
283
+
284
+ metricSavings.FCP = fcpSavings;
285
+ metricSavings.LCP = Math.max(lcpGraphSavings, lcpRecordSavings);
222
286
  } else {
223
287
  wastedMs = simulator.computeWastedMsFromWastedBytes(wastedBytes);
224
288
  }
@@ -232,6 +296,13 @@ class ByteEfficiencyAudit extends Audit {
232
296
  const details = Audit.makeOpportunityDetails(result.headings, results,
233
297
  {overallSavingsMs: wastedMs, overallSavingsBytes: wastedBytes, sortedBy});
234
298
 
299
+ // TODO: Remove from debug data once `metricSavings` is added to the LHR.
300
+ // For now, add it to debug data for visibility.
301
+ details.debugData = {
302
+ type: 'debugdata',
303
+ metricSavings,
304
+ };
305
+
235
306
  return {
236
307
  explanation: result.explanation,
237
308
  warnings: result.warnings,
@@ -240,6 +311,7 @@ class ByteEfficiencyAudit extends Audit {
240
311
  numericUnit: 'millisecond',
241
312
  score: ByteEfficiencyAudit.scoreForWastedMs(wastedMs),
242
313
  details,
314
+ metricSavings,
243
315
  };
244
316
  }
245
317
 
@@ -244,7 +244,7 @@ class PrioritizeLcpImage extends Audit {
244
244
  .find(element => element.traceEventType === 'largest-contentful-paint');
245
245
 
246
246
  if (!lcpElement || lcpElement.type !== 'image') {
247
- return {score: null, notApplicable: true};
247
+ return {score: null, notApplicable: true, metricSavings: {LCP: 0}};
248
248
  }
249
249
 
250
250
  const mainResource = await MainResource.request({devtoolsLog, URL}, context);
@@ -286,6 +286,7 @@ class PrioritizeLcpImage extends Audit {
286
286
  numericUnit: 'millisecond',
287
287
  displayValue: wastedMs ? str_(i18n.UIStrings.displayValueMsSavings, {wastedMs}) : '',
288
288
  details,
289
+ metricSavings: {LCP: wastedMs},
289
290
  };
290
291
  }
291
292
  }
@@ -154,6 +154,10 @@ class Redirects extends Audit {
154
154
  str_(i18n.UIStrings.displayValueMsSavings, {wastedMs: totalWastedMs}) :
155
155
  '',
156
156
  details,
157
+ metricSavings: {
158
+ LCP: totalWastedMs,
159
+ FCP: totalWastedMs,
160
+ },
157
161
  };
158
162
  }
159
163
  }
@@ -154,6 +154,9 @@ class UnsizedImages extends Audit {
154
154
  score: unsizedImages.length > 0 ? 0 : 1,
155
155
  notApplicable: images.length === 0,
156
156
  details: Audit.makeTableDetails(headings, unsizedImages),
157
+ metricSavings: {
158
+ CLS: 0,
159
+ },
157
160
  };
158
161
  }
159
162
  }
@@ -99,7 +99,7 @@ class JSBundles {
99
99
 
100
100
  const compiledUrl = SourceMap.scriptUrl || 'compiled.js';
101
101
  const mapUrl = SourceMap.sourceMapUrl || 'compiled.js.map';
102
- const map = new SDK.TextSourceMap(compiledUrl, mapUrl, rawMap);
102
+ const map = new SDK.SourceMap(compiledUrl, mapUrl, rawMap);
103
103
 
104
104
  const sizes = computeGeneratedFileSizes(map, script.length || 0, script.content || '');
105
105
 
@@ -15,4 +15,30 @@ export function calculateSumOfBlockingTime(topLevelEvents: Array<{
15
15
  end: number;
16
16
  duration: number;
17
17
  }>, startTimeMs: number, endTimeMs: number): number;
18
+ /**
19
+ * For TBT, We only want to consider tasks that fall in our time range
20
+ * - FCP and TTI for navigation mode
21
+ * - Trace start and trace end for timespan mode
22
+ *
23
+ * FCP is picked as `startTimeMs` because there is little risk of user input happening
24
+ * before FCP so Long Queuing Qelay regions do not harm user experience. Developers should be
25
+ * optimizing to reach FCP as fast as possible without having to worry about task lengths.
26
+ *
27
+ * TTI is picked as `endTimeMs` because we want a well defined end point for page load.
28
+ *
29
+ * @param {{start: number, end: number, duration: number}} event
30
+ * @param {number} startTimeMs Should be FCP in navigation mode and the trace start time in timespan mode
31
+ * @param {number} endTimeMs Should be TTI in navigation mode and the trace end time in timespan mode
32
+ * @param {{start: number, end: number, duration: number}} [topLevelEvent] Leave unset if `event` is top level. Has no effect if `event` has the same duration as `topLevelEvent`.
33
+ * @return {number}
34
+ */
35
+ export function calculateTbtImpactForEvent(event: {
36
+ start: number;
37
+ end: number;
38
+ duration: number;
39
+ }, startTimeMs: number, endTimeMs: number, topLevelEvent?: {
40
+ start: number;
41
+ end: number;
42
+ duration: number;
43
+ } | undefined): number;
18
44
  //# sourceMappingURL=tbt-utils.d.ts.map