lighthouse 12.8.2-dev.20251005 → 12.8.2-dev.20251006

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 (126) hide show
  1. package/cli/test/smokehouse/config/exclusions.js +0 -2
  2. package/core/audits/audit.js +0 -1
  3. package/core/audits/insights/cls-culprits-insight.js +1 -1
  4. package/core/audits/insights/dom-size-insight.js +6 -6
  5. package/core/audits/redirects.js +1 -0
  6. package/core/audits/server-response-time.d.ts +0 -5
  7. package/core/audits/server-response-time.js +12 -26
  8. package/core/computed/metrics/lcp-breakdown.js +1 -0
  9. package/core/config/default-config.js +20 -63
  10. package/core/config/experimental-config.js +1 -26
  11. package/core/config/filters.js +6 -9
  12. package/core/config/lr-desktop-config.js +0 -1
  13. package/core/config/lr-mobile-config.js +0 -1
  14. package/core/gather/gatherers/trace-elements.js +1 -0
  15. package/core/lib/proto-preprocessor.js +5 -22
  16. package/dist/report/bundle.esm.js +10 -49
  17. package/dist/report/flow.js +12 -51
  18. package/dist/report/standalone.js +11 -50
  19. package/flow-report/src/i18n/i18n.d.ts +4 -6
  20. package/package.json +3 -3
  21. package/report/assets/styles.css +0 -39
  22. package/report/renderer/api.js +0 -1
  23. package/report/renderer/category-renderer.js +6 -0
  24. package/report/renderer/components.js +1 -1
  25. package/report/renderer/dom.d.ts +0 -13
  26. package/report/renderer/dom.js +0 -38
  27. package/report/renderer/performance-category-renderer.d.ts +0 -26
  28. package/report/renderer/performance-category-renderer.js +10 -142
  29. package/report/renderer/report-ui-features.d.ts +0 -1
  30. package/report/renderer/report-ui-features.js +3 -13
  31. package/report/renderer/report-utils.d.ts +2 -3
  32. package/report/renderer/report-utils.js +4 -6
  33. package/report/types/report-renderer.d.ts +0 -6
  34. package/shared/localization/locales/ar-XB.json +0 -330
  35. package/shared/localization/locales/ar.json +0 -330
  36. package/shared/localization/locales/bg.json +0 -330
  37. package/shared/localization/locales/ca.json +0 -330
  38. package/shared/localization/locales/cs.json +0 -330
  39. package/shared/localization/locales/da.json +0 -330
  40. package/shared/localization/locales/de.json +0 -330
  41. package/shared/localization/locales/el.json +0 -330
  42. package/shared/localization/locales/en-GB.json +0 -330
  43. package/shared/localization/locales/en-US.json +26 -275
  44. package/shared/localization/locales/en-XA.json +0 -330
  45. package/shared/localization/locales/en-XL.json +26 -275
  46. package/shared/localization/locales/es-419.json +0 -330
  47. package/shared/localization/locales/es.json +0 -330
  48. package/shared/localization/locales/fi.json +0 -330
  49. package/shared/localization/locales/fil.json +0 -330
  50. package/shared/localization/locales/fr.json +0 -330
  51. package/shared/localization/locales/he.json +0 -330
  52. package/shared/localization/locales/hi.json +0 -330
  53. package/shared/localization/locales/hr.json +0 -330
  54. package/shared/localization/locales/hu.json +0 -330
  55. package/shared/localization/locales/id.json +0 -330
  56. package/shared/localization/locales/it.json +0 -330
  57. package/shared/localization/locales/ja.json +0 -330
  58. package/shared/localization/locales/ko.json +0 -330
  59. package/shared/localization/locales/lt.json +0 -330
  60. package/shared/localization/locales/lv.json +0 -330
  61. package/shared/localization/locales/nl.json +0 -330
  62. package/shared/localization/locales/no.json +0 -330
  63. package/shared/localization/locales/pl.json +0 -330
  64. package/shared/localization/locales/pt-PT.json +0 -330
  65. package/shared/localization/locales/pt.json +0 -330
  66. package/shared/localization/locales/ro.json +0 -330
  67. package/shared/localization/locales/ru.json +0 -330
  68. package/shared/localization/locales/sk.json +0 -330
  69. package/shared/localization/locales/sl.json +0 -330
  70. package/shared/localization/locales/sr-Latn.json +0 -330
  71. package/shared/localization/locales/sr.json +0 -330
  72. package/shared/localization/locales/sv.json +0 -330
  73. package/shared/localization/locales/ta.json +0 -330
  74. package/shared/localization/locales/te.json +0 -330
  75. package/shared/localization/locales/th.json +0 -330
  76. package/shared/localization/locales/tr.json +0 -330
  77. package/shared/localization/locales/uk.json +0 -330
  78. package/shared/localization/locales/vi.json +0 -330
  79. package/shared/localization/locales/zh-HK.json +0 -330
  80. package/shared/localization/locales/zh-TW.json +0 -330
  81. package/shared/localization/locales/zh.json +0 -330
  82. package/types/artifacts.d.ts +1 -0
  83. package/types/audit.d.ts +1 -1
  84. package/types/lhr/settings.d.ts +1 -1
  85. package/core/audits/byte-efficiency/duplicated-javascript.d.ts +0 -45
  86. package/core/audits/byte-efficiency/duplicated-javascript.js +0 -223
  87. package/core/audits/byte-efficiency/efficient-animated-content.d.ts +0 -22
  88. package/core/audits/byte-efficiency/efficient-animated-content.js +0 -93
  89. package/core/audits/byte-efficiency/legacy-javascript.d.ts +0 -28
  90. package/core/audits/byte-efficiency/legacy-javascript.js +0 -144
  91. package/core/audits/byte-efficiency/modern-image-formats.d.ts +0 -38
  92. package/core/audits/byte-efficiency/modern-image-formats.js +0 -187
  93. package/core/audits/byte-efficiency/render-blocking-resources.d.ts +0 -53
  94. package/core/audits/byte-efficiency/render-blocking-resources.js +0 -312
  95. package/core/audits/byte-efficiency/uses-long-cache-ttl.d.ts +0 -59
  96. package/core/audits/byte-efficiency/uses-long-cache-ttl.js +0 -293
  97. package/core/audits/byte-efficiency/uses-optimized-images.d.ts +0 -33
  98. package/core/audits/byte-efficiency/uses-optimized-images.js +0 -146
  99. package/core/audits/byte-efficiency/uses-responsive-images-snapshot.d.ts +0 -16
  100. package/core/audits/byte-efficiency/uses-responsive-images-snapshot.js +0 -106
  101. package/core/audits/byte-efficiency/uses-responsive-images.d.ts +0 -44
  102. package/core/audits/byte-efficiency/uses-responsive-images.js +0 -202
  103. package/core/audits/byte-efficiency/uses-text-compression.d.ts +0 -14
  104. package/core/audits/byte-efficiency/uses-text-compression.js +0 -108
  105. package/core/audits/critical-request-chains.d.ts +0 -44
  106. package/core/audits/critical-request-chains.js +0 -221
  107. package/core/audits/dobetterweb/dom-size.d.ts +0 -32
  108. package/core/audits/dobetterweb/dom-size.js +0 -182
  109. package/core/audits/dobetterweb/uses-http2.d.ts +0 -72
  110. package/core/audits/dobetterweb/uses-http2.js +0 -276
  111. package/core/audits/font-display.d.ts +0 -32
  112. package/core/audits/font-display.js +0 -195
  113. package/core/audits/largest-contentful-paint-element.d.ts +0 -34
  114. package/core/audits/largest-contentful-paint-element.js +0 -181
  115. package/core/audits/lcp-lazy-loaded.d.ts +0 -22
  116. package/core/audits/lcp-lazy-loaded.js +0 -115
  117. package/core/audits/prioritize-lcp-image.d.ts +0 -74
  118. package/core/audits/prioritize-lcp-image.js +0 -297
  119. package/core/audits/third-party-summary.d.ts +0 -78
  120. package/core/audits/third-party-summary.js +0 -236
  121. package/core/audits/uses-rel-preconnect.d.ts +0 -37
  122. package/core/audits/uses-rel-preconnect.js +0 -286
  123. package/core/audits/viewport.d.ts +0 -17
  124. package/core/audits/viewport.js +0 -87
  125. package/core/audits/work-during-interaction.d.ts +0 -81
  126. package/core/audits/work-during-interaction.js +0 -287
@@ -1,297 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2020 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import {Audit} from './audit.js';
8
- import * as i18n from '../lib/i18n/i18n.js';
9
- import {NetworkRequest} from '../lib/network-request.js';
10
- import {MainResource} from '../computed/main-resource.js';
11
- import {LanternLargestContentfulPaint} from '../computed/metrics/lantern-largest-contentful-paint.js';
12
- import {LoadSimulator} from '../computed/load-simulator.js';
13
- import {LCPImageRecord} from '../computed/lcp-image-record.js';
14
-
15
- const UIStrings = {
16
- /** Title of a lighthouse audit that tells a user to preload an image in order to improve their LCP time. */
17
- title: 'Preload Largest Contentful Paint image',
18
- /** Description of a lighthouse audit that tells a user to preload an image in order to improve their LCP time. */
19
- description: 'If the LCP element is dynamically added to the page, you should preload the ' +
20
- 'image in order to improve LCP. [Learn more about preloading LCP elements](https://web.dev/articles/optimize-lcp#optimize_when_the_resource_is_discovered).',
21
- };
22
-
23
- const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
24
-
25
- /**
26
- * @typedef {LH.Crdp.Network.Initiator['type']|'redirect'|'fallbackToMain'} InitiatorType
27
- * @typedef {Array<{url: string, initiatorType: InitiatorType}>} InitiatorPath
28
- */
29
-
30
- class PrioritizeLcpImage extends Audit {
31
- /**
32
- * @return {LH.Audit.Meta}
33
- */
34
- static get meta() {
35
- return {
36
- id: 'prioritize-lcp-image',
37
- title: str_(UIStrings.title),
38
- description: str_(UIStrings.description),
39
- supportedModes: ['navigation'],
40
- guidanceLevel: 4,
41
- requiredArtifacts: ['Trace', 'DevtoolsLog', 'GatherContext', 'URL', 'TraceElements',
42
- 'SourceMaps'],
43
- scoreDisplayMode: Audit.SCORING_MODES.METRIC_SAVINGS,
44
- };
45
- }
46
-
47
- /**
48
- *
49
- * @param {LH.Artifacts.NetworkRequest} request
50
- * @param {LH.Artifacts.NetworkRequest} mainResource
51
- * @param {InitiatorPath} initiatorPath
52
- * @return {boolean}
53
- */
54
- static shouldPreloadRequest(request, mainResource, initiatorPath) {
55
- // If it's already preloaded, no need to recommend it.
56
- if (request.isLinkPreload) return false;
57
- // It's not a request loaded over the network, don't recommend it.
58
- if (NetworkRequest.isNonNetworkRequest(request)) return false;
59
- // It's already discoverable from the main document (a path of [lcpRecord, mainResource]), don't recommend it.
60
- if (initiatorPath.length <= 2) return false;
61
- // Finally, return whether or not it belongs to the main frame
62
- return request.frameId === mainResource.frameId;
63
- }
64
-
65
- /**
66
- * @param {LH.Gatherer.Simulation.GraphNode} graph
67
- * @param {NetworkRequest} lcpRecord
68
- * @return {LH.Gatherer.Simulation.GraphNetworkNode|undefined}
69
- */
70
- static findLCPNode(graph, lcpRecord) {
71
- for (const {node} of graph.traverseGenerator()) {
72
- if (node.type !== 'network') continue;
73
- if (node.request.requestId === lcpRecord.requestId) {
74
- return node;
75
- }
76
- }
77
- }
78
-
79
- /**
80
- * Get the initiator path starting with lcpRecord back to mainResource, inclusive.
81
- * Navigation redirects *to* the mainResource are not included.
82
- * Path returned will always be at least [lcpRecord, mainResource].
83
- * @param {NetworkRequest} lcpRecord
84
- * @param {NetworkRequest} mainResource
85
- * @return {InitiatorPath}
86
- */
87
- static getLcpInitiatorPath(lcpRecord, mainResource) {
88
- /** @type {InitiatorPath} */
89
- const initiatorPath = [];
90
- let mainResourceReached = false;
91
- /** @type {NetworkRequest|undefined} */
92
- let request = lcpRecord;
93
-
94
- while (request) {
95
- mainResourceReached ||= request.requestId === mainResource.requestId;
96
-
97
- /** @type {InitiatorType} */
98
- let initiatorType = request.initiator?.type ?? 'other';
99
- // Initiator type usually comes from redirect, but 'redirect' is used for more informative debugData.
100
- if (request.initiatorRequest && request.initiatorRequest === request.redirectSource) {
101
- initiatorType = 'redirect';
102
- }
103
- // Sometimes the initiator chain is broken and the best that can be done is stitch
104
- // back to the main resource. Note this in the initiatorType.
105
- if (!request.initiatorRequest && !mainResourceReached) {
106
- initiatorType = 'fallbackToMain';
107
- }
108
-
109
- initiatorPath.push({url: request.url, initiatorType});
110
-
111
- // Can't preload before the main resource, so break off initiator path there.
112
- if (mainResourceReached) break;
113
-
114
- // Continue up chain, falling back to mainResource if chain is broken.
115
- request = request.initiatorRequest || mainResource;
116
- }
117
-
118
- return initiatorPath;
119
- }
120
-
121
- /**
122
- * @param {LH.Artifacts.NetworkRequest} mainResource
123
- * @param {LH.Gatherer.Simulation.GraphNode} graph
124
- * @param {NetworkRequest|undefined} lcpRecord
125
- * @return {{lcpNodeToPreload?: LH.Gatherer.Simulation.GraphNetworkNode, initiatorPath?: InitiatorPath}}
126
- */
127
- static getLCPNodeToPreload(mainResource, graph, lcpRecord) {
128
- if (!lcpRecord) return {};
129
- const lcpNode = PrioritizeLcpImage.findLCPNode(graph, lcpRecord);
130
- const initiatorPath = PrioritizeLcpImage.getLcpInitiatorPath(lcpRecord, mainResource);
131
- if (!lcpNode) return {initiatorPath};
132
-
133
- // eslint-disable-next-line max-len
134
- const shouldPreload = PrioritizeLcpImage.shouldPreloadRequest(lcpRecord, mainResource, initiatorPath);
135
- const lcpNodeToPreload = shouldPreload ? lcpNode : undefined;
136
-
137
- return {
138
- lcpNodeToPreload,
139
- initiatorPath,
140
- };
141
- }
142
-
143
- /**
144
- * Computes the estimated effect of preloading the LCP image.
145
- * @param {LH.Artifacts.TraceElement} lcpElement
146
- * @param {LH.Gatherer.Simulation.GraphNetworkNode|undefined} lcpNode
147
- * @param {LH.Gatherer.Simulation.GraphNode} graph
148
- * @param {LH.Gatherer.Simulation.Simulator} simulator
149
- * @return {{wastedMs: number, results: Array<{node: LH.Audit.Details.NodeValue, url: string, wastedMs: number}>}}
150
- */
151
- static computeWasteWithGraph(lcpElement, lcpNode, graph, simulator) {
152
- if (!lcpNode) {
153
- return {
154
- wastedMs: 0,
155
- results: [],
156
- };
157
- }
158
-
159
- const modifiedGraph = graph.cloneWithRelationships();
160
-
161
- // Store the IDs of the LCP Node's dependencies for later
162
- /** @type {Set<string>} */
163
- const dependenciesIds = new Set();
164
- for (const node of lcpNode.getDependencies()) {
165
- dependenciesIds.add(node.id);
166
- }
167
-
168
- /** @type {LH.Gatherer.Simulation.GraphNode|null} */
169
- let modifiedLCPNode = null;
170
- /** @type {LH.Gatherer.Simulation.GraphNode|null} */
171
- let mainDocumentNode = null;
172
-
173
- for (const {node} of modifiedGraph.traverseGenerator()) {
174
- if (node.type !== 'network') continue;
175
-
176
- if (node.isMainDocument()) {
177
- mainDocumentNode = node;
178
- } else if (node.id === lcpNode.id) {
179
- modifiedLCPNode = node;
180
- }
181
- }
182
-
183
- if (!mainDocumentNode) {
184
- // Should always find the main document node
185
- throw new Error('Could not find main document node');
186
- }
187
-
188
- if (!modifiedLCPNode) {
189
- // Should always find the LCP node as well or else this function wouldn't have been called
190
- throw new Error('Could not find the LCP node');
191
- }
192
-
193
- // Preload will request the resource as soon as its discovered in the main document.
194
- // Reflect this change in the dependencies in our modified graph.
195
- modifiedLCPNode.removeAllDependencies();
196
- modifiedLCPNode.addDependency(mainDocumentNode);
197
-
198
- const simulationBeforeChanges = simulator.simulate(graph);
199
- const simulationAfterChanges = simulator.simulate(modifiedGraph);
200
- const lcpTimingsBefore = simulationBeforeChanges.nodeTimings.get(lcpNode);
201
- if (!lcpTimingsBefore) throw new Error('Impossible - node timings should never be undefined');
202
- const lcpTimingsAfter = simulationAfterChanges.nodeTimings.get(modifiedLCPNode);
203
- if (!lcpTimingsAfter) throw new Error('Impossible - node timings should never be undefined');
204
- /** @type {Map<String, LH.Gatherer.Simulation.GraphNode>} */
205
- const modifiedNodesById = Array.from(simulationAfterChanges.nodeTimings.keys())
206
- .reduce((map, node) => map.set(node.id, node), new Map());
207
-
208
- // Even with preload, the image can't be painted before it's even inserted into the DOM.
209
- // New LCP time will be the max of image download and image in DOM (endTime of its deps).
210
- let maxDependencyEndTime = 0;
211
- for (const nodeId of Array.from(dependenciesIds)) {
212
- const node = modifiedNodesById.get(nodeId);
213
- if (!node) throw new Error('Impossible - node should never be undefined');
214
- const timings = simulationAfterChanges.nodeTimings.get(node);
215
- const endTime = timings?.endTime || 0;
216
- maxDependencyEndTime = Math.max(maxDependencyEndTime, endTime);
217
- }
218
-
219
- const wastedMs = lcpTimingsBefore.endTime -
220
- Math.max(lcpTimingsAfter.endTime, maxDependencyEndTime);
221
-
222
- return {
223
- wastedMs,
224
- results: [{
225
- node: Audit.makeNodeItem(lcpElement.node),
226
- url: lcpNode.request.url,
227
- wastedMs,
228
- }],
229
- };
230
- }
231
-
232
- /**
233
- * @param {LH.Artifacts} artifacts
234
- * @param {LH.Audit.Context} context
235
- * @return {Promise<LH.Audit.Product>}
236
- */
237
- static async audit(artifacts, context) {
238
- const gatherContext = artifacts.GatherContext;
239
- const trace = artifacts.Trace;
240
- const devtoolsLog = artifacts.DevtoolsLog;
241
- const {URL, SourceMaps} = artifacts;
242
- const settings = context.settings;
243
- const metricData =
244
- {trace, devtoolsLog, gatherContext, settings, URL, SourceMaps, simulator: null};
245
- const lcpElement = artifacts.TraceElements
246
- .find(element => element.traceEventType === 'largest-contentful-paint');
247
-
248
- if (!lcpElement || lcpElement.type !== 'image') {
249
- return {score: null, notApplicable: true, metricSavings: {LCP: 0}};
250
- }
251
-
252
- const mainResource = await MainResource.request({devtoolsLog, URL}, context);
253
- const lanternLCP = await LanternLargestContentfulPaint.request(metricData, context);
254
- const simulator = await LoadSimulator.request({devtoolsLog, settings}, context);
255
-
256
- const lcpImageRecord = await LCPImageRecord.request({trace, devtoolsLog}, context);
257
- const graph = lanternLCP.pessimisticGraph;
258
- // Note: if moving to LCPAllFrames, mainResource would need to be the LCP frame's main resource.
259
- const {lcpNodeToPreload, initiatorPath} = PrioritizeLcpImage.getLCPNodeToPreload(mainResource,
260
- graph, lcpImageRecord);
261
-
262
- const {results, wastedMs} =
263
- PrioritizeLcpImage.computeWasteWithGraph(lcpElement, lcpNodeToPreload, graph, simulator);
264
-
265
- /** @type {LH.Audit.Details.Opportunity['headings']} */
266
- const headings = [
267
- {key: 'node', valueType: 'node', label: ''},
268
- {key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
269
- {key: 'wastedMs', valueType: 'timespanMs', label: str_(i18n.UIStrings.columnWastedMs)},
270
- ];
271
- const details = Audit.makeOpportunityDetails(headings, results,
272
- {overallSavingsMs: wastedMs, sortedBy: ['wastedMs']});
273
-
274
- // If LCP element was an image and had valid network records (regardless of
275
- // if it should be preloaded), it will be found first in the `initiatorPath`.
276
- // Otherwise path and length will be undefined.
277
- if (initiatorPath) {
278
- details.debugData = {
279
- type: 'debugdata',
280
- initiatorPath,
281
- pathLength: initiatorPath.length,
282
- };
283
- }
284
-
285
- return {
286
- score: results.length ? 0 : 1,
287
- numericValue: wastedMs,
288
- numericUnit: 'millisecond',
289
- displayValue: wastedMs ? str_(i18n.UIStrings.displayValueMsSavings, {wastedMs}) : '',
290
- details,
291
- metricSavings: {LCP: wastedMs},
292
- };
293
- }
294
- }
295
-
296
- export default PrioritizeLcpImage;
297
- export {UIStrings};
@@ -1,78 +0,0 @@
1
- export default ThirdPartySummary;
2
- export type Summary = {
3
- mainThreadTime: number;
4
- transferSize: number;
5
- blockingTime: number;
6
- tbtImpact: number;
7
- };
8
- export type URLSummary = {
9
- transferSize: number;
10
- blockingTime: number;
11
- tbtImpact: number;
12
- url: string | LH.IcuMessage;
13
- };
14
- export type SummaryMaps = {
15
- /**
16
- * Map of impact summaries for each entity.
17
- */
18
- byEntity: Map<LH.Artifacts.Entity, Summary>;
19
- /**
20
- * Map of impact summaries for each URL.
21
- */
22
- byURL: Map<string, Summary>;
23
- /**
24
- * Map of URLs under each entity.
25
- */
26
- urls: Map<LH.Artifacts.Entity, string[]>;
27
- };
28
- /**
29
- * @typedef Summary
30
- * @property {number} mainThreadTime
31
- * @property {number} transferSize
32
- * @property {number} blockingTime
33
- * @property {number} tbtImpact
34
- */
35
- /**
36
- * @typedef URLSummary
37
- * @property {number} transferSize
38
- * @property {number} blockingTime
39
- * @property {number} tbtImpact
40
- * @property {string | LH.IcuMessage} url
41
- */
42
- /** @typedef SummaryMaps
43
- * @property {Map<LH.Artifacts.Entity, Summary>} byEntity Map of impact summaries for each entity.
44
- * @property {Map<string, Summary>} byURL Map of impact summaries for each URL.
45
- * @property {Map<LH.Artifacts.Entity, string[]>} urls Map of URLs under each entity.
46
- */
47
- declare class ThirdPartySummary extends Audit {
48
- /**
49
- *
50
- * @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
51
- * @param {Array<LH.Artifacts.TBTImpactTask>} tbtImpactTasks
52
- * @param {number} cpuMultiplier
53
- * @param {LH.Artifacts.EntityClassification} entityClassification
54
- * @return {SummaryMaps}
55
- */
56
- static getSummaries(networkRecords: Array<LH.Artifacts.NetworkRequest>, tbtImpactTasks: Array<LH.Artifacts.TBTImpactTask>, cpuMultiplier: number, entityClassification: LH.Artifacts.EntityClassification): SummaryMaps;
57
- /**
58
- * @param {LH.Artifacts.Entity} entity
59
- * @param {SummaryMaps} summaries
60
- * @return {Array<URLSummary>}
61
- */
62
- static makeSubItems(entity: LH.Artifacts.Entity, summaries: SummaryMaps): Array<URLSummary>;
63
- /**
64
- * @param {LH.Artifacts} artifacts
65
- * @param {LH.Audit.Context} context
66
- * @return {Promise<LH.Audit.Product>}
67
- */
68
- static audit(artifacts: LH.Artifacts, context: LH.Audit.Context): Promise<LH.Audit.Product>;
69
- }
70
- export namespace UIStrings {
71
- let title: string;
72
- let failureTitle: string;
73
- let description: string;
74
- let columnThirdParty: string;
75
- let displayValue: string;
76
- }
77
- import { Audit } from './audit.js';
78
- //# sourceMappingURL=third-party-summary.d.ts.map
@@ -1,236 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2019 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import {Audit} from './audit.js';
8
- import {EntityClassification} from '../computed/entity-classification.js';
9
- import * as i18n from '../lib/i18n/i18n.js';
10
- import {NetworkRecords} from '../computed/network-records.js';
11
- import {getJavaScriptURLs, getAttributableURLForTask} from '../lib/tracehouse/task-summary.js';
12
- import {TBTImpactTasks} from '../computed/tbt-impact-tasks.js';
13
-
14
- const UIStrings = {
15
- /** Title of a diagnostic audit that provides details about the code on a web page that the user doesn't control (referred to as "third-party code"). This descriptive title is shown to users when the amount is acceptable and no user action is required. */
16
- title: 'Minimize third-party usage',
17
- /** Title of a diagnostic audit that provides details about the code on a web page that the user doesn't control (referred to as "third-party code"). This imperative title is shown to users when there is a significant amount of page execution time caused by third-party code that should be reduced. */
18
- failureTitle: 'Reduce the impact of third-party code',
19
- /** Description of a Lighthouse audit that identifies the code on the page that the user doesn't control. 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. */
20
- description: 'Third-party code can significantly impact load performance. ' +
21
- 'Limit the number of redundant third-party providers and try to load third-party code after ' +
22
- 'your page has primarily finished loading. ' +
23
- '[Learn how to minimize third-party impact](https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/loading-third-party-javascript/).',
24
- /** Label for a table column that displays the name of a third-party provider that potentially links to their website. */
25
- columnThirdParty: 'Third-Party',
26
- /** Summary text for the result of a Lighthouse audit that identifies the code on a web page that the user doesn't control (referred to as "third-party code"). This text summarizes the number of distinct entities that were found on the page. */
27
- displayValue: 'Third-party code blocked the main thread for ' +
28
- `{timeInMs, number, milliseconds}\xa0ms`,
29
- };
30
-
31
- const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
32
-
33
- // A page passes when all third-party code blocks for less than 250 ms.
34
- const PASS_THRESHOLD_IN_MS = 250;
35
-
36
- /**
37
- * @typedef Summary
38
- * @property {number} mainThreadTime
39
- * @property {number} transferSize
40
- * @property {number} blockingTime
41
- * @property {number} tbtImpact
42
- */
43
-
44
- /**
45
- * @typedef URLSummary
46
- * @property {number} transferSize
47
- * @property {number} blockingTime
48
- * @property {number} tbtImpact
49
- * @property {string | LH.IcuMessage} url
50
- */
51
-
52
- /** @typedef SummaryMaps
53
- * @property {Map<LH.Artifacts.Entity, Summary>} byEntity Map of impact summaries for each entity.
54
- * @property {Map<string, Summary>} byURL Map of impact summaries for each URL.
55
- * @property {Map<LH.Artifacts.Entity, string[]>} urls Map of URLs under each entity.
56
- */
57
-
58
- class ThirdPartySummary extends Audit {
59
- /**
60
- * @return {LH.Audit.Meta}
61
- */
62
- static get meta() {
63
- return {
64
- id: 'third-party-summary',
65
- title: str_(UIStrings.title),
66
- failureTitle: str_(UIStrings.failureTitle),
67
- description: str_(UIStrings.description),
68
- guidanceLevel: 1,
69
- scoreDisplayMode: Audit.SCORING_MODES.METRIC_SAVINGS,
70
- requiredArtifacts: ['Trace', 'DevtoolsLog', 'URL', 'GatherContext', 'SourceMaps'],
71
- };
72
- }
73
-
74
- /**
75
- *
76
- * @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
77
- * @param {Array<LH.Artifacts.TBTImpactTask>} tbtImpactTasks
78
- * @param {number} cpuMultiplier
79
- * @param {LH.Artifacts.EntityClassification} entityClassification
80
- * @return {SummaryMaps}
81
- */
82
- static getSummaries(networkRecords, tbtImpactTasks, cpuMultiplier, entityClassification) {
83
- /** @type {Map<string, Summary>} */
84
- const byURL = new Map();
85
- /** @type {Map<LH.Artifacts.Entity, Summary>} */
86
- const byEntity = new Map();
87
- const defaultSummary = {mainThreadTime: 0, blockingTime: 0, transferSize: 0, tbtImpact: 0};
88
-
89
- for (const request of networkRecords) {
90
- const urlSummary = byURL.get(request.url) || {...defaultSummary};
91
- urlSummary.transferSize += request.transferSize;
92
- byURL.set(request.url, urlSummary);
93
- }
94
-
95
- const jsURLs = getJavaScriptURLs(networkRecords);
96
-
97
- for (const task of tbtImpactTasks) {
98
- const attributableURL = getAttributableURLForTask(task, jsURLs);
99
-
100
- const urlSummary = byURL.get(attributableURL) || {...defaultSummary};
101
- const taskDuration = task.selfTime * cpuMultiplier;
102
- // The amount of time spent on main thread is the sum of all durations.
103
- urlSummary.mainThreadTime += taskDuration;
104
- // Blocking time is the amount of time spent on the main thread *over* 50ms.
105
- // This value is interpolated because not all tasks attributed to this URL are at the top level.
106
- //
107
- // Note that this is not totally equivalent to the TBT definition since it fails to account for
108
- // the FCP&TTI bounds of TBT.
109
- urlSummary.blockingTime += task.selfBlockingTime;
110
- // TBT impact is similar to blocking time, but it accounts for the FCP&TTI bounds of TBT.
111
- urlSummary.tbtImpact += task.selfTbtImpact;
112
- byURL.set(attributableURL, urlSummary);
113
- }
114
-
115
- // Map each URL's stat to a particular entity.
116
- /** @type {Map<LH.Artifacts.Entity, string[]>} */
117
- const urls = new Map();
118
- for (const [url, urlSummary] of byURL.entries()) {
119
- const entity = entityClassification.entityByUrl.get(url);
120
- if (!entity) {
121
- byURL.delete(url);
122
- continue;
123
- }
124
-
125
- const entitySummary = byEntity.get(entity) || {...defaultSummary};
126
- entitySummary.transferSize += urlSummary.transferSize;
127
- entitySummary.mainThreadTime += urlSummary.mainThreadTime;
128
- entitySummary.blockingTime += urlSummary.blockingTime;
129
- entitySummary.tbtImpact += urlSummary.tbtImpact;
130
- byEntity.set(entity, entitySummary);
131
-
132
- const entityURLs = urls.get(entity) || [];
133
- entityURLs.push(url);
134
- urls.set(entity, entityURLs);
135
- }
136
-
137
- return {byURL, byEntity, urls};
138
- }
139
-
140
- /**
141
- * @param {LH.Artifacts.Entity} entity
142
- * @param {SummaryMaps} summaries
143
- * @return {Array<URLSummary>}
144
- */
145
- static makeSubItems(entity, summaries) {
146
- const entityURLs = summaries.urls.get(entity) || [];
147
- const items = entityURLs
148
- .map(url => /** @type {URLSummary} */ ({url, ...summaries.byURL.get(url)}))
149
- // Sort by blocking time first, then transfer size to break ties.
150
- .sort((a, b) => (b.blockingTime - a.blockingTime) || (b.transferSize - a.transferSize));
151
-
152
- return items;
153
- }
154
-
155
- /**
156
- * @param {LH.Artifacts} artifacts
157
- * @param {LH.Audit.Context} context
158
- * @return {Promise<LH.Audit.Product>}
159
- */
160
- static async audit(artifacts, context) {
161
- const settings = context.settings || {};
162
- const devtoolsLog = artifacts.DevtoolsLog;
163
- const networkRecords = await NetworkRecords.request(devtoolsLog, context);
164
- const classifiedEntities = await EntityClassification.request(
165
- {URL: artifacts.URL, devtoolsLog}, context);
166
- const firstPartyEntity = classifiedEntities.firstParty;
167
-
168
- const metricComputationData = Audit.makeMetricComputationDataInput(artifacts, context);
169
- const tbtImpactTasks = await TBTImpactTasks.request(metricComputationData, context);
170
-
171
- const multiplier = settings.throttlingMethod === 'simulate' ?
172
- settings.throttling.cpuSlowdownMultiplier : 1;
173
-
174
- const summaries = ThirdPartySummary.getSummaries(
175
- networkRecords, tbtImpactTasks, multiplier, classifiedEntities);
176
- const overallSummary = {wastedBytes: 0, wastedMs: 0, tbtImpact: 0};
177
-
178
- const results = Array.from(summaries.byEntity.entries())
179
- // Don't consider the page we're on to be third-party.
180
- // e.g. Facebook SDK isn't a third-party script on facebook.com
181
- .filter(([entity]) => !(firstPartyEntity && firstPartyEntity === entity))
182
- .map(([entity, stats]) => {
183
- overallSummary.wastedBytes += stats.transferSize;
184
- overallSummary.wastedMs += stats.blockingTime;
185
- overallSummary.tbtImpact += stats.tbtImpact;
186
-
187
- return {
188
- ...stats,
189
- entity: entity.name,
190
- subItems: {
191
- type: /** @type {const} */ ('subitems'),
192
- items: ThirdPartySummary.makeSubItems(entity, summaries),
193
- },
194
- };
195
- })
196
- // Sort by blocking time first, then transfer size to break ties.
197
- .sort((a, b) => (b.blockingTime - a.blockingTime) || (b.transferSize - a.transferSize));
198
-
199
- /** @type {LH.Audit.Details.Table['headings']} */
200
- const headings = [
201
- /* eslint-disable max-len */
202
- {key: 'entity', valueType: 'text', label: str_(UIStrings.columnThirdParty), subItemsHeading: {key: 'url', valueType: 'url'}},
203
- {key: 'transferSize', granularity: 1, valueType: 'bytes', label: str_(i18n.UIStrings.columnTransferSize), subItemsHeading: {key: 'transferSize'}},
204
- {key: 'blockingTime', granularity: 1, valueType: 'ms', label: str_(i18n.UIStrings.columnBlockingTime), subItemsHeading: {key: 'blockingTime'}},
205
- /* eslint-enable max-len */
206
- ];
207
-
208
- if (!results.length) {
209
- return {
210
- score: 1,
211
- notApplicable: true,
212
- metricSavings: {TBT: 0},
213
- };
214
- }
215
-
216
- const details = Audit.makeTableDetails(headings, results,
217
- {...overallSummary, isEntityGrouped: true});
218
-
219
- const passed = overallSummary.wastedMs <= PASS_THRESHOLD_IN_MS;
220
-
221
- return {
222
- score: Number(passed),
223
- scoreDisplayMode: passed ? Audit.SCORING_MODES.INFORMATIVE : undefined,
224
- displayValue: str_(UIStrings.displayValue, {
225
- timeInMs: overallSummary.wastedMs,
226
- }),
227
- details,
228
- metricSavings: {
229
- TBT: Math.round(overallSummary.tbtImpact),
230
- },
231
- };
232
- }
233
- }
234
-
235
- export default ThirdPartySummary;
236
- export {UIStrings};
@@ -1,37 +0,0 @@
1
- export default UsesRelPreconnectAudit;
2
- declare class UsesRelPreconnectAudit extends Audit {
3
- /**
4
- * Check if record has valid timing
5
- * @param {LH.Artifacts.NetworkRequest} record
6
- * @return {boolean}
7
- */
8
- static hasValidTiming(record: LH.Artifacts.NetworkRequest): boolean;
9
- /**
10
- * Check is the connection is already open
11
- * @param {LH.Artifacts.NetworkRequest} record
12
- * @return {boolean}
13
- */
14
- static hasAlreadyConnectedToOrigin(record: LH.Artifacts.NetworkRequest): boolean;
15
- /**
16
- * Check is the connection has started before the socket idle time
17
- * @param {LH.Artifacts.NetworkRequest} record
18
- * @param {LH.Artifacts.NetworkRequest} mainResource
19
- * @return {boolean}
20
- */
21
- static socketStartTimeIsBelowThreshold(record: LH.Artifacts.NetworkRequest, mainResource: LH.Artifacts.NetworkRequest): boolean;
22
- /**
23
- * @param {LH.Artifacts} artifacts
24
- * @param {LH.Audit.Context} context
25
- * @return {Promise<LH.Audit.Product>}
26
- */
27
- static audit(artifacts: LH.Artifacts, context: LH.Audit.Context): Promise<LH.Audit.Product>;
28
- }
29
- export namespace UIStrings {
30
- let title: string;
31
- let description: string;
32
- let unusedWarning: string;
33
- let crossoriginWarning: string;
34
- let tooManyPreconnectLinksWarning: string;
35
- }
36
- import { Audit } from './audit.js';
37
- //# sourceMappingURL=uses-rel-preconnect.d.ts.map