lighthouse 12.8.2-dev.20251005 → 12.8.2-dev.20251007

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 (142) 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 +11 -7
  5. package/core/audits/insights/insight-audit.d.ts +4 -2
  6. package/core/audits/insights/insight-audit.js +22 -3
  7. package/core/audits/predictive-perf.js +2 -2
  8. package/core/audits/seo/crawlable-anchors.js +2 -3
  9. package/core/audits/server-response-time.d.ts +0 -5
  10. package/core/audits/server-response-time.js +12 -26
  11. package/core/computed/metrics/lcp-breakdown.d.ts +10 -5
  12. package/core/computed/metrics/lcp-breakdown.js +50 -22
  13. package/core/computed/metrics/time-to-first-byte.js +33 -10
  14. package/core/computed/metrics/timing-summary.js +3 -2
  15. package/core/config/default-config.js +20 -63
  16. package/core/config/experimental-config.js +1 -26
  17. package/core/config/filters.js +6 -9
  18. package/core/config/lr-desktop-config.js +0 -1
  19. package/core/config/lr-mobile-config.js +0 -1
  20. package/core/gather/gatherers/anchor-elements.js +8 -24
  21. package/core/gather/gatherers/inspector-issues.js +1 -28
  22. package/core/gather/gatherers/trace-elements.d.ts +0 -9
  23. package/core/gather/gatherers/trace-elements.js +0 -35
  24. package/core/lib/network-request.d.ts +0 -7
  25. package/core/lib/network-request.js +0 -16
  26. package/core/lib/proto-preprocessor.js +5 -22
  27. package/dist/report/bundle.esm.js +10 -49
  28. package/dist/report/flow.js +12 -51
  29. package/dist/report/standalone.js +11 -50
  30. package/flow-report/src/i18n/i18n.d.ts +4 -6
  31. package/package.json +4 -5
  32. package/report/assets/styles.css +0 -39
  33. package/report/renderer/api.js +0 -1
  34. package/report/renderer/category-renderer.js +6 -0
  35. package/report/renderer/components.js +1 -1
  36. package/report/renderer/dom.d.ts +0 -13
  37. package/report/renderer/dom.js +0 -38
  38. package/report/renderer/performance-category-renderer.d.ts +0 -26
  39. package/report/renderer/performance-category-renderer.js +10 -142
  40. package/report/renderer/report-ui-features.d.ts +0 -1
  41. package/report/renderer/report-ui-features.js +3 -13
  42. package/report/renderer/report-utils.d.ts +2 -3
  43. package/report/renderer/report-utils.js +4 -6
  44. package/report/types/report-renderer.d.ts +0 -6
  45. package/shared/localization/locales/ar-XB.json +20 -341
  46. package/shared/localization/locales/ar.json +20 -341
  47. package/shared/localization/locales/bg.json +9 -330
  48. package/shared/localization/locales/ca.json +9 -330
  49. package/shared/localization/locales/cs.json +9 -330
  50. package/shared/localization/locales/da.json +9 -330
  51. package/shared/localization/locales/de.json +9 -330
  52. package/shared/localization/locales/el.json +9 -330
  53. package/shared/localization/locales/en-GB.json +9 -330
  54. package/shared/localization/locales/en-US.json +44 -293
  55. package/shared/localization/locales/en-XA.json +0 -330
  56. package/shared/localization/locales/en-XL.json +44 -293
  57. package/shared/localization/locales/es-419.json +9 -330
  58. package/shared/localization/locales/es.json +9 -330
  59. package/shared/localization/locales/fi.json +9 -330
  60. package/shared/localization/locales/fil.json +9 -330
  61. package/shared/localization/locales/fr.json +9 -330
  62. package/shared/localization/locales/he.json +31 -352
  63. package/shared/localization/locales/hi.json +9 -330
  64. package/shared/localization/locales/hr.json +9 -330
  65. package/shared/localization/locales/hu.json +9 -330
  66. package/shared/localization/locales/id.json +9 -330
  67. package/shared/localization/locales/it.json +9 -330
  68. package/shared/localization/locales/ja.json +9 -330
  69. package/shared/localization/locales/ko.json +10 -331
  70. package/shared/localization/locales/lt.json +9 -330
  71. package/shared/localization/locales/lv.json +10 -331
  72. package/shared/localization/locales/nl.json +9 -330
  73. package/shared/localization/locales/no.json +9 -330
  74. package/shared/localization/locales/pl.json +9 -330
  75. package/shared/localization/locales/pt-PT.json +9 -330
  76. package/shared/localization/locales/pt.json +9 -330
  77. package/shared/localization/locales/ro.json +10 -331
  78. package/shared/localization/locales/ru.json +9 -330
  79. package/shared/localization/locales/sk.json +9 -330
  80. package/shared/localization/locales/sl.json +9 -330
  81. package/shared/localization/locales/sr-Latn.json +9 -330
  82. package/shared/localization/locales/sr.json +9 -330
  83. package/shared/localization/locales/sv.json +9 -330
  84. package/shared/localization/locales/ta.json +9 -330
  85. package/shared/localization/locales/te.json +10 -331
  86. package/shared/localization/locales/th.json +9 -330
  87. package/shared/localization/locales/tr.json +9 -330
  88. package/shared/localization/locales/uk.json +9 -330
  89. package/shared/localization/locales/vi.json +9 -330
  90. package/shared/localization/locales/zh-HK.json +9 -330
  91. package/shared/localization/locales/zh-TW.json +10 -331
  92. package/shared/localization/locales/zh.json +9 -330
  93. package/types/artifacts.d.ts +5 -6
  94. package/types/audit.d.ts +1 -1
  95. package/types/lhr/settings.d.ts +1 -1
  96. package/core/audits/byte-efficiency/duplicated-javascript.d.ts +0 -45
  97. package/core/audits/byte-efficiency/duplicated-javascript.js +0 -223
  98. package/core/audits/byte-efficiency/efficient-animated-content.d.ts +0 -22
  99. package/core/audits/byte-efficiency/efficient-animated-content.js +0 -93
  100. package/core/audits/byte-efficiency/legacy-javascript.d.ts +0 -28
  101. package/core/audits/byte-efficiency/legacy-javascript.js +0 -144
  102. package/core/audits/byte-efficiency/modern-image-formats.d.ts +0 -38
  103. package/core/audits/byte-efficiency/modern-image-formats.js +0 -187
  104. package/core/audits/byte-efficiency/render-blocking-resources.d.ts +0 -53
  105. package/core/audits/byte-efficiency/render-blocking-resources.js +0 -312
  106. package/core/audits/byte-efficiency/uses-long-cache-ttl.d.ts +0 -59
  107. package/core/audits/byte-efficiency/uses-long-cache-ttl.js +0 -293
  108. package/core/audits/byte-efficiency/uses-optimized-images.d.ts +0 -33
  109. package/core/audits/byte-efficiency/uses-optimized-images.js +0 -146
  110. package/core/audits/byte-efficiency/uses-responsive-images-snapshot.d.ts +0 -16
  111. package/core/audits/byte-efficiency/uses-responsive-images-snapshot.js +0 -106
  112. package/core/audits/byte-efficiency/uses-responsive-images.d.ts +0 -44
  113. package/core/audits/byte-efficiency/uses-responsive-images.js +0 -202
  114. package/core/audits/byte-efficiency/uses-text-compression.d.ts +0 -14
  115. package/core/audits/byte-efficiency/uses-text-compression.js +0 -108
  116. package/core/audits/critical-request-chains.d.ts +0 -44
  117. package/core/audits/critical-request-chains.js +0 -221
  118. package/core/audits/dobetterweb/dom-size.d.ts +0 -32
  119. package/core/audits/dobetterweb/dom-size.js +0 -182
  120. package/core/audits/dobetterweb/uses-http2.d.ts +0 -72
  121. package/core/audits/dobetterweb/uses-http2.js +0 -276
  122. package/core/audits/font-display.d.ts +0 -32
  123. package/core/audits/font-display.js +0 -195
  124. package/core/audits/largest-contentful-paint-element.d.ts +0 -34
  125. package/core/audits/largest-contentful-paint-element.js +0 -181
  126. package/core/audits/lcp-lazy-loaded.d.ts +0 -22
  127. package/core/audits/lcp-lazy-loaded.js +0 -115
  128. package/core/audits/prioritize-lcp-image.d.ts +0 -74
  129. package/core/audits/prioritize-lcp-image.js +0 -297
  130. package/core/audits/third-party-summary.d.ts +0 -78
  131. package/core/audits/third-party-summary.js +0 -236
  132. package/core/audits/uses-rel-preconnect.d.ts +0 -37
  133. package/core/audits/uses-rel-preconnect.js +0 -286
  134. package/core/audits/viewport.d.ts +0 -17
  135. package/core/audits/viewport.js +0 -87
  136. package/core/audits/work-during-interaction.d.ts +0 -81
  137. package/core/audits/work-during-interaction.js +0 -287
  138. package/core/computed/critical-request-chains.d.ts +0 -42
  139. package/core/computed/critical-request-chains.js +0 -143
  140. package/core/computed/viewport-meta.d.ts +0 -37
  141. package/core/computed/viewport-meta.js +0 -71
  142. package/types/internal/metaviewport-parser.d.ts +0 -13
@@ -1,287 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2022 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import {Audit} from './audit.js';
8
- import {Responsiveness} from '../computed/metrics/responsiveness.js';
9
- import {ProcessedTrace} from '../computed/processed-trace.js';
10
- import * as i18n from '../lib/i18n/i18n.js';
11
- import {NetworkRecords} from '../computed/network-records.js';
12
- import {MainThreadTasks} from '../lib/tracehouse/main-thread-tasks.js';
13
- import {taskGroups} from '../lib/tracehouse/task-groups.js';
14
- import {TraceProcessor} from '../lib/tracehouse/trace-processor.js';
15
- import {getExecutionTimingsByURL} from '../lib/tracehouse/task-summary.js';
16
- import InteractionToNextPaint from './metrics/interaction-to-next-paint.js';
17
-
18
- /** @typedef {import('../computed/metrics/responsiveness.js').EventTimingEvent} EventTimingEvent */
19
- /** @typedef {import('../lib/tracehouse/main-thread-tasks.js').TaskNode} TaskNode */
20
-
21
- const TASK_THRESHOLD = 1;
22
-
23
- const UIStrings = {
24
- /** Title of a diagnostic audit that provides detail on the main thread work the browser did during a key user interaction. This descriptive title is shown to users when the amount is acceptable and no user action is required. */
25
- title: 'Minimizes work during key interaction',
26
- /** Title of a diagnostic audit that provides detail on the main thread work the browser did during a key user interaction. This imperative title is shown to users when there is a significant amount of execution time that could be reduced. */
27
- failureTitle: 'Minimize work during key interaction',
28
- /** Description of the work-during-interaction metric. This description is displayed within a tooltip when the user hovers on the metric name to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
29
- description: 'This is the thread-blocking work occurring during the Interaction to Next Paint measurement. [Learn more about the Interaction to Next Paint metric](https://web.dev/articles/inp).',
30
- /** Label for a column in a data table; entries will be information on the time that the browser is delayed before responding to user input. Ideally fits within a ~40 character limit. */
31
- inputDelay: 'Input delay',
32
- /** Label for a column in a data table; entries will be information on the time taken by code processing user input that delays a response to the user. Ideally fits within a ~40 character limit. */
33
- processingDuration: 'Processing duration',
34
- /** Label for a column in a data table; entries will be information on the time that the browser is delayed before presenting a response to user input on screen. Ideally fits within a ~40 character limit. */
35
- presentationDelay: 'Presentation delay',
36
- /**
37
- * @description Summary text that identifies the time the browser took to process a user interaction.
38
- * @example {mousedown} interactionType
39
- */
40
- displayValue: `{timeInMs, number, milliseconds}\xa0ms spent on event '{interactionType}'`,
41
- /** Label for a column in a data table; entries will the UI element that was the target of a user interaction (for example, a button that was clicked on). Ideally fits within a ~40 character limit. */
42
- eventTarget: 'Event target',
43
- };
44
-
45
- const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
46
-
47
- /**
48
- * @fileoverview This metric gives a high-percentile measure of responsiveness to input.
49
- */
50
- class WorkDuringInteraction extends Audit {
51
- /**
52
- * @return {LH.Audit.Meta}
53
- */
54
- static get meta() {
55
- return {
56
- id: 'work-during-interaction',
57
- title: str_(UIStrings.title),
58
- failureTitle: str_(UIStrings.failureTitle),
59
- description: str_(UIStrings.description),
60
- scoreDisplayMode: Audit.SCORING_MODES.METRIC_SAVINGS,
61
- supportedModes: ['timespan'],
62
- guidanceLevel: 1,
63
- requiredArtifacts: ['Trace', 'DevtoolsLog', 'TraceElements'],
64
- };
65
- }
66
-
67
- /**
68
- * @param {TaskNode} task
69
- * @param {TaskNode|undefined} parent
70
- * @param {number} startTs
71
- * @param {number} endTs
72
- * @return {number}
73
- */
74
- static recursivelyClipTasks(task, parent, startTs, endTs) {
75
- const taskEventStart = task.event.ts;
76
- const taskEventEnd = task.endEvent?.ts ?? task.event.ts + Number(task.event.dur || 0);
77
-
78
- task.startTime = Math.max(startTs, Math.min(endTs, taskEventStart)) / 1000;
79
- task.endTime = Math.max(startTs, Math.min(endTs, taskEventEnd)) / 1000;
80
- task.duration = task.endTime - task.startTime;
81
-
82
- const childTime = task.children
83
- .map(child => WorkDuringInteraction.recursivelyClipTasks(child, task, startTs, endTs))
84
- .reduce((sum, child) => sum + child, 0);
85
- task.selfTime = task.duration - childTime;
86
- return task.duration;
87
- }
88
-
89
- /**
90
- * Clip the tasks by the start and end points. Take the easy route and drop
91
- * to duration 0 if out of bounds, since only durations are needed in the
92
- * end (for now).
93
- * Assumes owned tasks, so modifies in place. Can be called multiple times on
94
- * the same `tasks` because always computed from original event timing.
95
- * @param {Array<TaskNode>} tasks
96
- * @param {number} startTs
97
- * @param {number} endTs
98
- */
99
- static clipTasksByTs(tasks, startTs, endTs) {
100
- for (const task of tasks) {
101
- if (task.parent) continue;
102
- WorkDuringInteraction.recursivelyClipTasks(task, undefined, startTs, endTs);
103
- }
104
- }
105
-
106
- /**
107
- * @param {EventTimingEvent} interactionEvent
108
- */
109
- static getPhaseTimes(interactionEvent) {
110
- const interactionData = interactionEvent.args.data;
111
- const startTs = interactionEvent.ts;
112
- const navStart = startTs - interactionData.timeStamp * 1000;
113
- const processingStartTs = navStart + interactionData.processingStart * 1000;
114
- const processingEndTs = navStart + interactionData.processingEnd * 1000;
115
- const endTs = startTs + interactionData.duration * 1000;
116
- return {
117
- inputDelay: {startTs, endTs: processingStartTs},
118
- processingDuration: {startTs: processingStartTs, endTs: processingEndTs},
119
- presentationDelay: {startTs: processingEndTs, endTs},
120
- };
121
- }
122
-
123
- /**
124
- * @param {EventTimingEvent} interactionEvent
125
- * @param {LH.Trace} trace
126
- * @param {LH.Artifacts.ProcessedTrace} processedTrace
127
- * @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
128
- * @return {{table: LH.Audit.Details.Table, phases: Record<string, {startTs: number, endTs: number}>}}
129
- */
130
- static getThreadBreakdownTable(interactionEvent, trace, processedTrace, networkRecords) {
131
- // Limit to interactionEvent's thread.
132
- // TODO(bckenny): limit to interactionEvent's navigation.
133
- const threadEvents = TraceProcessor.filteredTraceSort(trace.traceEvents, evt => {
134
- return evt.pid === interactionEvent.pid && evt.tid === interactionEvent.tid;
135
- });
136
- const traceEndTs = threadEvents.reduce((endTs, evt) => {
137
- return Math.max(evt.ts + (evt.dur || 0), endTs);
138
- }, 0);
139
- // frames is only used for URL attribution, so can include all frames, even if OOPIF.
140
- const {frames} = processedTrace;
141
- const threadTasks = MainThreadTasks.getMainThreadTasks(threadEvents, frames, traceEndTs);
142
-
143
- const phases = WorkDuringInteraction.getPhaseTimes(interactionEvent);
144
-
145
- /** @type {LH.Audit.Details.TableItem[]} */
146
- const items = [];
147
- for (const [phaseName, phaseTimes] of Object.entries(phases)) {
148
- // Clip tasks to start and end time.
149
- WorkDuringInteraction.clipTasksByTs(threadTasks, phaseTimes.startTs, phaseTimes.endTs);
150
- const executionTimings = getExecutionTimingsByURL(threadTasks, networkRecords);
151
-
152
- const results = [];
153
- for (const [url, timingByGroupId] of executionTimings) {
154
- const totalExecutionTimeForURL = Object.values(timingByGroupId)
155
- .reduce((total, timespanMs) => total + timespanMs);
156
-
157
- const scriptingTotal = timingByGroupId[taskGroups.scriptEvaluation.id] || 0;
158
- const layoutTotal = timingByGroupId[taskGroups.styleLayout.id] || 0;
159
- const renderTotal = timingByGroupId[taskGroups.paintCompositeRender.id] || 0;
160
-
161
- results.push({
162
- url: url,
163
- total: totalExecutionTimeForURL,
164
- scripting: scriptingTotal,
165
- layout: layoutTotal,
166
- render: renderTotal,
167
- });
168
- }
169
-
170
- const filteredResults = results
171
- .filter(result => result.total > TASK_THRESHOLD)
172
- .sort((a, b) => b.total - a.total);
173
-
174
- items.push({
175
- phase: str_(UIStrings[/** @type {keyof UIStrings} */ (phaseName)]),
176
- total: (phaseTimes.endTs - phaseTimes.startTs) / 1000,
177
- subItems: {
178
- type: 'subitems',
179
- items: filteredResults,
180
- },
181
- });
182
- }
183
-
184
- /** @type {LH.Audit.Details.Table['headings']} */
185
- const headings = [
186
- /* eslint-disable max-len */
187
- {key: 'phase', valueType: 'text', subItemsHeading: {key: 'url', valueType: 'url'}, label: 'Phase'},
188
- {key: 'total', valueType: 'ms', subItemsHeading: {key: 'total', granularity: 1, valueType: 'ms'}, granularity: 1, label: 'Total time'},
189
- {key: null, valueType: 'ms', subItemsHeading: {key: 'scripting', granularity: 1, valueType: 'ms'}, label: 'Script evaluation'},
190
- {key: null, valueType: 'ms', subItemsHeading: {key: 'layout', granularity: 1, valueType: 'ms'}, label: taskGroups.styleLayout.label},
191
- {key: null, valueType: 'ms', subItemsHeading: {key: 'render', granularity: 1, valueType: 'ms'}, label: taskGroups.paintCompositeRender.label},
192
- /* eslint-enable max-len */
193
- ];
194
-
195
- return {
196
- table: Audit.makeTableDetails(headings, items, {sortedBy: ['total']}),
197
- phases,
198
- };
199
- }
200
-
201
- /**
202
- * @param {LH.Artifacts['TraceElements']} traceElements
203
- * @return {LH.Audit.Details.Table | undefined}
204
- */
205
- static getTraceElementTable(traceElements) {
206
- const responsivenessElement = traceElements.find(el => el.traceEventType === 'responsiveness');
207
- if (!responsivenessElement) return;
208
-
209
- /** @type {LH.Audit.Details.Table['headings']} */
210
- const headings = [
211
- {key: 'node', valueType: 'node', label: str_(UIStrings.eventTarget)},
212
- ];
213
- const elementItems = [{node: Audit.makeNodeItem(responsivenessElement.node)}];
214
-
215
- return Audit.makeTableDetails(headings, elementItems);
216
- }
217
-
218
- /**
219
- * @param {LH.Artifacts} artifacts
220
- * @param {LH.Audit.Context} context
221
- * @return {Promise<LH.Audit.Product>}
222
- */
223
- static async audit(artifacts, context) {
224
- const {settings} = context;
225
- // TODO: responsiveness isn't yet supported by lantern.
226
- if (settings.throttlingMethod === 'simulate') {
227
- return {
228
- score: null,
229
- notApplicable: true,
230
- metricSavings: {INP: 0},
231
- };
232
- }
233
-
234
- const trace = artifacts.Trace;
235
- const metricData = {trace, settings};
236
- const interactionEvent = await Responsiveness.request(metricData, context);
237
- // If no interaction, diagnostic audit is n/a.
238
- if (interactionEvent === null) {
239
- return {
240
- score: null,
241
- notApplicable: true,
242
- metricSavings: {INP: 0},
243
- };
244
- }
245
-
246
- const auditDetailsItems = [];
247
-
248
- const traceElementItem = WorkDuringInteraction.getTraceElementTable(artifacts.TraceElements);
249
- if (traceElementItem) auditDetailsItems.push(traceElementItem);
250
-
251
- const devtoolsLog = artifacts.DevtoolsLog;
252
- // Network records will usually be empty for timespans.
253
- const networkRecords = await NetworkRecords.request(devtoolsLog, context);
254
- const processedTrace = await ProcessedTrace.request(trace, context);
255
- const {table: breakdownTable, phases} = WorkDuringInteraction.getThreadBreakdownTable(
256
- interactionEvent, trace, processedTrace, networkRecords);
257
- auditDetailsItems.push(breakdownTable);
258
-
259
- const interactionType = interactionEvent.args.data.type;
260
- auditDetailsItems.push({
261
- type: /** @type {const} */ ('debugdata'),
262
- interactionType,
263
- phases,
264
- });
265
-
266
- const duration = interactionEvent.args.data.duration;
267
- const displayValue = str_(UIStrings.displayValue, {timeInMs: duration, interactionType});
268
-
269
- const passed = duration < InteractionToNextPaint.defaultOptions.p10;
270
-
271
- return {
272
- score: passed ? 1 : 0,
273
- scoreDisplayMode: passed ? Audit.SCORING_MODES.INFORMATIVE : undefined,
274
- displayValue,
275
- details: {
276
- type: 'list',
277
- items: auditDetailsItems,
278
- },
279
- metricSavings: {
280
- INP: duration,
281
- },
282
- };
283
- }
284
- }
285
-
286
- export default WorkDuringInteraction;
287
- export {UIStrings};
@@ -1,42 +0,0 @@
1
- export { CriticalRequestChainsComputed as CriticalRequestChains };
2
- declare const CriticalRequestChainsComputed: typeof CriticalRequestChains & {
3
- request: (dependencies: {
4
- URL: LH.Artifacts["URL"];
5
- SourceMaps: LH.Artifacts["SourceMaps"];
6
- devtoolsLog: LH.DevtoolsLog;
7
- trace: LH.Trace;
8
- settings: LH.Audit.Context["settings"];
9
- }, context: LH.Artifacts.ComputedContext) => Promise<import("../index.js").Artifacts.CriticalRequestNode>;
10
- };
11
- declare class CriticalRequestChains {
12
- /**
13
- * For now, we use network priorities as a proxy for "render-blocking"/critical-ness.
14
- * It's imperfect, but there is not a higher-fidelity signal available yet.
15
- * @see https://docs.google.com/document/d/1bCDuq9H1ih9iNjgzyAL0gpwNFiEP4TZS-YLRp_RuMlc
16
- * @param {Lantern.Types.NetworkRequest} request
17
- * @param {Lantern.Types.NetworkRequest} mainResource
18
- * @return {boolean}
19
- */
20
- static isCritical(request: Lantern.Types.NetworkRequest, mainResource: Lantern.Types.NetworkRequest): boolean;
21
- /**
22
- * Create a tree of critical requests.
23
- * @param {LH.Artifacts.NetworkRequest} mainResource
24
- * @param {LH.Gatherer.Simulation.GraphNode} graph
25
- * @return {LH.Artifacts.CriticalRequestNode}
26
- */
27
- static extractChainsFromGraph(mainResource: LH.Artifacts.NetworkRequest, graph: LH.Gatherer.Simulation.GraphNode): LH.Artifacts.CriticalRequestNode;
28
- /**
29
- * @param {{URL: LH.Artifacts['URL'], SourceMaps: LH.Artifacts['SourceMaps'], devtoolsLog: LH.DevtoolsLog, trace: LH.Trace, settings: LH.Audit.Context['settings']}} data
30
- * @param {LH.Artifacts.ComputedContext} context
31
- * @return {Promise<LH.Artifacts.CriticalRequestNode>}
32
- */
33
- static compute_(data: {
34
- URL: LH.Artifacts["URL"];
35
- SourceMaps: LH.Artifacts["SourceMaps"];
36
- devtoolsLog: LH.DevtoolsLog;
37
- trace: LH.Trace;
38
- settings: LH.Audit.Context["settings"];
39
- }, context: LH.Artifacts.ComputedContext): Promise<LH.Artifacts.CriticalRequestNode>;
40
- }
41
- import * as Lantern from '../lib/lantern/lantern.js';
42
- //# sourceMappingURL=critical-request-chains.d.ts.map
@@ -1,143 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2016 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import * as Lantern from '../lib/lantern/lantern.js';
8
- import {makeComputedArtifact} from './computed-artifact.js';
9
- import {NetworkRequest} from '../lib/network-request.js';
10
- import {MainResource} from './main-resource.js';
11
- import {PageDependencyGraph} from './page-dependency-graph.js';
12
-
13
- class CriticalRequestChains {
14
- /**
15
- * For now, we use network priorities as a proxy for "render-blocking"/critical-ness.
16
- * It's imperfect, but there is not a higher-fidelity signal available yet.
17
- * @see https://docs.google.com/document/d/1bCDuq9H1ih9iNjgzyAL0gpwNFiEP4TZS-YLRp_RuMlc
18
- * @param {Lantern.Types.NetworkRequest} request
19
- * @param {Lantern.Types.NetworkRequest} mainResource
20
- * @return {boolean}
21
- */
22
- static isCritical(request, mainResource) {
23
- if (!mainResource) {
24
- throw new Error('mainResource not provided');
25
- }
26
-
27
- // The main resource is always critical.
28
- if (request.requestId === mainResource.requestId) return true;
29
-
30
- // Treat any preloaded resource as non-critical
31
- if (request.isLinkPreload) {
32
- return false;
33
- }
34
-
35
- // Whenever a request is a redirect, we don't know if it's critical until we resolve the final
36
- // destination. At that point we can assign all the properties (priority, resourceType) of the
37
- // final request back to the redirect(s) that led to it.
38
- // See https://github.com/GoogleChrome/lighthouse/pull/6704
39
- while (request.redirectDestination) {
40
- request = request.redirectDestination;
41
- }
42
-
43
- // Iframes are considered High Priority but they are not render blocking
44
- const isIframe = request.resourceType === NetworkRequest.TYPES.Document &&
45
- request.frameId !== mainResource.frameId;
46
- // XHRs are fetched at High priority, but we exclude them, as they are unlikely to be critical
47
- // Images are also non-critical.
48
- // Treat any missed images, primarily favicons, as non-critical resources
49
- /** @type {Array<LH.Crdp.Network.ResourceType>} */
50
- const nonCriticalResourceTypes = [
51
- NetworkRequest.TYPES.Image,
52
- NetworkRequest.TYPES.XHR,
53
- NetworkRequest.TYPES.Fetch,
54
- NetworkRequest.TYPES.EventSource,
55
- ];
56
- if (nonCriticalResourceTypes.includes(request.resourceType || 'Other') ||
57
- isIframe ||
58
- request.mimeType && request.mimeType.startsWith('image/')) {
59
- return false;
60
- }
61
-
62
- // Requests that have no initiatorRequest are typically ambiguous late-load assets.
63
- // Even on the off chance they were important, we don't have any parent to display for them.
64
- if (!request.initiatorRequest) return false;
65
-
66
- return ['VeryHigh', 'High', 'Medium'].includes(request.priority);
67
- }
68
-
69
- /**
70
- * Create a tree of critical requests.
71
- * @param {LH.Artifacts.NetworkRequest} mainResource
72
- * @param {LH.Gatherer.Simulation.GraphNode} graph
73
- * @return {LH.Artifacts.CriticalRequestNode}
74
- */
75
- static extractChainsFromGraph(mainResource, graph) {
76
- /** @type {LH.Artifacts.CriticalRequestNode} */
77
- const rootNode = {};
78
-
79
- /**
80
- * @param {LH.Artifacts.NetworkRequest[]} path
81
- */
82
- function addChain(path) {
83
- let currentNode = rootNode;
84
-
85
- for (const record of path) {
86
- if (!currentNode[record.requestId]) {
87
- currentNode[record.requestId] = {
88
- request: record,
89
- children: {},
90
- };
91
- }
92
-
93
- currentNode = currentNode[record.requestId].children;
94
- }
95
- }
96
-
97
- // By default `traverse` will discover nodes in BFS-order regardless of dependencies, but
98
- // here we need traversal in a topological sort order. We'll visit a node only when its
99
- // dependencies have been met.
100
- const seenNodes = new Set();
101
- /** @param {LH.Gatherer.Simulation.GraphNode} node */
102
- function getNextNodes(node) {
103
- return node.getDependents().filter(n => n.getDependencies().every(d => seenNodes.has(d)));
104
- }
105
-
106
- graph.traverse((node, traversalPath) => {
107
- seenNodes.add(node);
108
- if (node.type !== 'network') return;
109
- if (!CriticalRequestChains.isCritical(node.request, mainResource)) return;
110
-
111
- const networkPath = traversalPath
112
- .filter(n => n.type === 'network')
113
- .reverse()
114
- .map(node => node.rawRequest);
115
-
116
- // Ignore if some ancestor is not a critical request.
117
- if (networkPath.some(r => !CriticalRequestChains.isCritical(r, mainResource))) return;
118
-
119
- // Ignore non-network things (like data urls).
120
- if (NetworkRequest.isNonNetworkRequest(node.request)) return;
121
-
122
- addChain(networkPath);
123
- }, getNextNodes);
124
-
125
- return rootNode;
126
- }
127
-
128
- /**
129
- * @param {{URL: LH.Artifacts['URL'], SourceMaps: LH.Artifacts['SourceMaps'], devtoolsLog: LH.DevtoolsLog, trace: LH.Trace, settings: LH.Audit.Context['settings']}} data
130
- * @param {LH.Artifacts.ComputedContext} context
131
- * @return {Promise<LH.Artifacts.CriticalRequestNode>}
132
- */
133
- static async compute_(data, context) {
134
- const mainResource = await MainResource.request(data, context);
135
- const graph = await PageDependencyGraph.request({...data, fromTrace: false}, context);
136
-
137
- return CriticalRequestChains.extractChainsFromGraph(mainResource, graph);
138
- }
139
- }
140
-
141
- const CriticalRequestChainsComputed = makeComputedArtifact(CriticalRequestChains,
142
- ['URL', 'SourceMaps', 'devtoolsLog', 'trace', 'settings']);
143
- export {CriticalRequestChainsComputed as CriticalRequestChains};
@@ -1,37 +0,0 @@
1
- export { ViewportMetaComputed as ViewportMeta };
2
- export type ViewportMetaResult = {
3
- /**
4
- * Whether the page has any viewport tag.
5
- */
6
- hasViewportTag: boolean;
7
- /**
8
- * Whether the viewport tag is optimized for mobile screens.
9
- */
10
- isMobileOptimized: boolean;
11
- /**
12
- * Warnings if the parser encountered invalid content in the viewport tag.
13
- */
14
- parserWarnings: Array<string>;
15
- /**
16
- * The `content` attribute value, if a viewport was defined.
17
- */
18
- rawContentString: string | undefined;
19
- };
20
- declare const ViewportMetaComputed: typeof ViewportMeta & {
21
- request: (dependencies: {
22
- name?: string;
23
- content?: string;
24
- property?: string;
25
- httpEquiv?: string;
26
- charset?: string;
27
- node: import("../index.js").Artifacts.NodeDetails;
28
- }[], context: LH.Artifacts.ComputedContext) => Promise<ViewportMetaResult>;
29
- };
30
- declare class ViewportMeta {
31
- /**
32
- * @param {LH.GathererArtifacts['MetaElements']} MetaElements
33
- * @return {Promise<ViewportMetaResult>}
34
- */
35
- static compute_(MetaElements: LH.GathererArtifacts["MetaElements"]): Promise<ViewportMetaResult>;
36
- }
37
- //# sourceMappingURL=viewport-meta.d.ts.map
@@ -1,71 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2019 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import Parser from 'metaviewport-parser';
8
-
9
- import {makeComputedArtifact} from './computed-artifact.js';
10
-
11
- class ViewportMeta {
12
- /**
13
- * @param {LH.GathererArtifacts['MetaElements']} MetaElements
14
- * @return {Promise<ViewportMetaResult>}
15
- */
16
- static async compute_(MetaElements) {
17
- const viewportMeta = MetaElements.find(meta => meta.name === 'viewport');
18
-
19
- if (!viewportMeta) {
20
- return {
21
- hasViewportTag: false,
22
- isMobileOptimized: false,
23
- parserWarnings: [],
24
- rawContentString: undefined,
25
- };
26
- }
27
-
28
- const warnings = [];
29
- const rawContentString = viewportMeta.content || '';
30
- const parsedProps = Parser.parseMetaViewPortContent(rawContentString);
31
-
32
- if (Object.keys(parsedProps.unknownProperties).length) {
33
- warnings.push(`Invalid properties found: ${JSON.stringify(parsedProps.unknownProperties)}`);
34
- }
35
- if (Object.keys(parsedProps.invalidValues).length) {
36
- warnings.push(`Invalid values found: ${JSON.stringify(parsedProps.invalidValues)}`);
37
- }
38
-
39
- const viewportProps = parsedProps.validProperties;
40
- const initialScale = Number(viewportProps['initial-scale']);
41
-
42
- if (!isNaN(initialScale) && initialScale < 1) {
43
- return {
44
- hasViewportTag: true,
45
- isMobileOptimized: false,
46
- parserWarnings: warnings,
47
- rawContentString,
48
- };
49
- }
50
-
51
- const isMobileOptimized = Boolean(viewportProps.width || initialScale);
52
-
53
- return {
54
- hasViewportTag: true,
55
- isMobileOptimized,
56
- parserWarnings: warnings,
57
- rawContentString,
58
- };
59
- }
60
- }
61
-
62
- const ViewportMetaComputed = makeComputedArtifact(ViewportMeta, null);
63
- export {ViewportMetaComputed as ViewportMeta};
64
-
65
- /**
66
- * @typedef {object} ViewportMetaResult
67
- * @property {boolean} hasViewportTag Whether the page has any viewport tag.
68
- * @property {boolean} isMobileOptimized Whether the viewport tag is optimized for mobile screens.
69
- * @property {Array<string>} parserWarnings Warnings if the parser encountered invalid content in the viewport tag.
70
- * @property {string|undefined} rawContentString The `content` attribute value, if a viewport was defined.
71
- */
@@ -1,13 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2018 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- declare module 'metaviewport-parser' {
8
- export function parseMetaViewPortContent(S: string): {
9
- validProperties: {[p: string]: number | string},
10
- unknownProperties: {[p: string]: number | string},
11
- invalidValues: {[p: string]: number | string};
12
- };
13
- }