lighthouse 13.6.0-dev.20261111 → 13.6.0-dev.20261116

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 (107) hide show
  1. package/.agents/skills/update-ard-port/SKILL.md +1 -1
  2. package/cli/bin.js +8 -3
  3. package/cli/open-file.d.ts +7 -0
  4. package/cli/open-file.js +48 -0
  5. package/cli/printer.js +1 -1
  6. package/cli/run.js +6 -4
  7. package/cli/sentry-prompt.js +2 -1
  8. package/cli/test/smokehouse/frontends/smokehouse-bin.js +1 -1
  9. package/cli/test/smokehouse/lighthouse-runners/cli.js +1 -2
  10. package/cli/test/smokehouse/report-assert.js +1 -2
  11. package/cli/test/smokehouse/smokehouse.js +1 -2
  12. package/core/audits/autocomplete.js +1 -2
  13. package/core/audits/bootup-time.js +1 -2
  14. package/core/audits/errors-in-console.js +1 -2
  15. package/core/audits/mainthread-work-breakdown.js +1 -2
  16. package/core/audits/metrics.d.ts +2 -2
  17. package/core/audits/metrics.js +1 -1
  18. package/core/computed/computed-artifact.js +1 -2
  19. package/core/computed/entity-classification.d.ts +3 -3
  20. package/core/computed/entity-classification.js +5 -3
  21. package/core/computed/js-bundles.js +1 -2
  22. package/core/computed/load-simulator.d.ts +5 -3
  23. package/core/computed/load-simulator.js +9 -2
  24. package/core/computed/metrics/responsiveness.d.ts +5 -3
  25. package/core/computed/metrics/responsiveness.js +1 -1
  26. package/core/computed/metrics/time-to-first-byte.js +3 -1
  27. package/core/computed/metrics/timing-summary.d.ts +7 -5
  28. package/core/computed/metrics/timing-summary.js +3 -4
  29. package/core/computed/navigation-insights.d.ts +5 -3
  30. package/core/computed/navigation-insights.js +1 -1
  31. package/core/computed/network-analysis.js +1 -2
  32. package/core/computed/page-dependency-graph.d.ts +5 -3
  33. package/core/computed/page-dependency-graph.js +1 -1
  34. package/core/computed/trace-engine-result.d.ts +7 -5
  35. package/core/computed/trace-engine-result.js +9 -5
  36. package/core/computed/unused-css.d.ts +2 -2
  37. package/core/computed/unused-css.js +1 -1
  38. package/core/config/config.js +1 -2
  39. package/core/gather/base-artifacts.js +1 -2
  40. package/core/gather/driver/environment.js +1 -2
  41. package/core/gather/driver/execution-context.js +2 -0
  42. package/core/gather/driver/navigation.js +1 -2
  43. package/core/gather/driver/network-monitor.js +1 -2
  44. package/core/gather/driver/prepare.js +1 -2
  45. package/core/gather/driver/storage.js +1 -2
  46. package/core/gather/driver/target-manager.js +1 -2
  47. package/core/gather/driver/wait-for-condition.js +6 -5
  48. package/core/gather/driver.js +1 -2
  49. package/core/gather/gatherers/agentic/ard.js +1 -1
  50. package/core/gather/gatherers/agentic/llms-txt.js +1 -2
  51. package/core/gather/gatherers/css-usage.js +5 -1
  52. package/core/gather/gatherers/image-elements.js +1 -2
  53. package/core/gather/gatherers/seo/robots-txt.js +1 -2
  54. package/core/gather/gatherers/stacks.js +1 -2
  55. package/core/gather/gatherers/stylesheets.js +10 -3
  56. package/core/gather/navigation-runner.js +1 -1
  57. package/core/gather/runner-helpers.js +1 -2
  58. package/core/gather/session.js +1 -2
  59. package/core/gather/snapshot-runner.js +1 -2
  60. package/core/gather/timespan-runner.js +1 -2
  61. package/core/lib/asset-saver.js +1 -2
  62. package/core/lib/csp-evaluator.js +1 -1
  63. package/core/lib/i18n/i18n.js +1 -2
  64. package/core/lib/lantern-trace-saver.js +19 -13
  65. package/core/lib/lighthouse-logger.d.ts +127 -0
  66. package/core/lib/lighthouse-logger.js +319 -0
  67. package/core/lib/median-run.d.ts +16 -6
  68. package/core/lib/median-run.js +13 -6
  69. package/core/lib/network-recorder.js +1 -2
  70. package/core/lib/network-request.d.ts +2 -2
  71. package/core/lib/network-request.js +1 -1
  72. package/core/lib/page-functions.js +4 -3
  73. package/core/lib/script-helpers.d.ts +23 -8
  74. package/core/lib/script-helpers.js +7 -6
  75. package/core/lib/sentry-reporter.d.ts +59 -0
  76. package/core/lib/sentry-reporter.js +281 -0
  77. package/core/lib/sentry.d.ts +7 -7
  78. package/core/lib/sentry.js +31 -39
  79. package/core/lib/stack-packs.js +1 -1
  80. package/core/lib/timing-trace-saver.d.ts +2 -2
  81. package/core/lib/timing-trace-saver.js +1 -1
  82. package/core/lib/tracehouse/main-thread-tasks.d.ts +7 -0
  83. package/core/lib/tracehouse/main-thread-tasks.js +18 -6
  84. package/core/lib/tracehouse/task-summary.d.ts +16 -4
  85. package/core/lib/tracehouse/task-summary.js +6 -5
  86. package/core/lib/tracehouse/trace-processor.d.ts +6 -6
  87. package/core/lib/tracehouse/trace-processor.js +1 -1
  88. package/core/lib/traces/metric-trace-events.js +1 -2
  89. package/core/lib/url-utils.d.ts +4 -4
  90. package/core/lib/url-utils.js +1 -1
  91. package/core/runner.js +1 -2
  92. package/dist/report/bundle.esm.js +10 -10
  93. package/dist/report/flow.js +13 -13
  94. package/dist/report/standalone.js +11 -11
  95. package/package.json +9 -12
  96. package/report/renderer/text-encoding.d.ts +3 -5
  97. package/report/renderer/text-encoding.js +19 -33
  98. package/report/types/augment-dom.d.ts +0 -4
  99. package/shared/util.js +10 -2
  100. package/third-party/ard/README.md +2 -2
  101. package/third-party/ard/ard.js +1 -1
  102. package/third-party/ard/schema-validator.js +42 -2
  103. package/tsconfig.json +2 -42
  104. package/types/artifacts.d.ts +7 -1
  105. package/types/internal/node.d.ts +1 -0
  106. package/types/internal/test.d.ts +5 -0
  107. package/report/types/buffer.d.ts +0 -19
@@ -0,0 +1,127 @@
1
+ export default Log;
2
+ export type LoggerFn = {
3
+ (formatter: any, ...args: any[]): void;
4
+ color: string | number;
5
+ enabled: boolean;
6
+ };
7
+ declare class Log {
8
+ static events: Emitter;
9
+ /**
10
+ * @param {string} title
11
+ * @param {Array<any>} argsArray
12
+ */
13
+ static _logToStdErr(title: string, argsArray: Array<any>): void;
14
+ /**
15
+ * @param {string} title
16
+ * @return {LoggerFn}
17
+ */
18
+ static loggerfn(title: string): LoggerFn;
19
+ /**
20
+ * @param {string} level
21
+ */
22
+ static setLevel(level: string): void;
23
+ /**
24
+ * A simple formatting utility for event logging.
25
+ * @param {string} prefix
26
+ * @param {{method?: string, params?: Record<string, any>}} data A JSON-serializable object of event data to log.
27
+ * @param {string=} level Optional logging level. Defaults to 'log'.
28
+ */
29
+ static formatProtocol(prefix: string, data: {
30
+ method?: string;
31
+ params?: Record<string, any>;
32
+ }, level?: string | undefined): void;
33
+ /**
34
+ * @return {boolean}
35
+ */
36
+ static isVerbose(): boolean;
37
+ /**
38
+ * @param {{msg: string, id: string, args?: any[]}} status
39
+ * @param {'log'|'verbose'|'warn'|'error'} [level]
40
+ */
41
+ static time({ msg, id, args }: {
42
+ msg: string;
43
+ id: string;
44
+ args?: any[];
45
+ }, level?: "log" | "verbose" | "warn" | "error"): void;
46
+ /**
47
+ * @param {{msg: string, id: string, args?: any[]}} status
48
+ * @param {'log'|'verbose'|'warn'|'error'} [level]
49
+ */
50
+ static timeEnd({ msg, id, args }: {
51
+ msg: string;
52
+ id: string;
53
+ args?: any[];
54
+ }, level?: "log" | "verbose" | "warn" | "error"): void;
55
+ /**
56
+ * @param {string} title
57
+ * @param {...any} args
58
+ */
59
+ static log(title: string, ...args: any[]): void;
60
+ /**
61
+ * @param {string} title
62
+ * @param {...any} args
63
+ */
64
+ static warn(title: string, ...args: any[]): void;
65
+ /**
66
+ * @param {string} title
67
+ * @param {...any} args
68
+ */
69
+ static error(title: string, ...args: any[]): void;
70
+ /**
71
+ * @param {string} title
72
+ * @param {...any} args
73
+ */
74
+ static verbose(title: string, ...args: any[]): void;
75
+ /**
76
+ * Add surrounding escape sequences to turn a string green when logged.
77
+ * @param {string} str
78
+ * @return {string}
79
+ */
80
+ static greenify(str: string): string;
81
+ /**
82
+ * Add surrounding escape sequences to turn a string red when logged.
83
+ * @param {string} str
84
+ * @return {string}
85
+ */
86
+ static redify(str: string): string;
87
+ static get green(): string;
88
+ static get red(): string;
89
+ static get purple(): string;
90
+ static get reset(): string;
91
+ static get bold(): string;
92
+ static get dim(): string;
93
+ static get tick(): "√" | "✓";
94
+ static get cross(): "×" | "✘";
95
+ /**
96
+ * @return {PerformanceEntry[]}
97
+ */
98
+ static takeTimeEntries(): PerformanceEntry[];
99
+ /**
100
+ * @return {PerformanceEntry[]}
101
+ */
102
+ static getTimeEntries(): PerformanceEntry[];
103
+ }
104
+ /** @typedef {{(formatter: any, ...args: any[]): void, color: string|number, enabled: boolean}} LoggerFn */
105
+ /** @extends {EventEmitter<Record<string, any[]>>} */
106
+ declare class Emitter extends EventEmitter<Record<string, any[]>> {
107
+ /**
108
+ * @param {ConstructorParameters<typeof EventEmitter>[0]} [options]
109
+ */
110
+ constructor(options?: ConstructorParameters<typeof EventEmitter>[0]);
111
+ /**
112
+ * Fires off all status updates. Listen with
113
+ * `log.events.addListener('status', callback)`
114
+ * @param {string} title
115
+ * @param {Array<any>} argsArray
116
+ */
117
+ issueStatus(title: string, argsArray: Array<any>): void;
118
+ /**
119
+ * Fires off all warnings. Listen with
120
+ * `log.events.addListener('warning', callback)`
121
+ * @param {string} title
122
+ * @param {Array<any>} argsArray
123
+ */
124
+ issueWarning(title: string, argsArray: Array<any>): void;
125
+ }
126
+ import { EventEmitter } from 'events';
127
+ //# sourceMappingURL=lighthouse-logger.d.ts.map
@@ -0,0 +1,319 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2016 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import process from 'process';
8
+ import {EventEmitter} from 'events';
9
+
10
+ import debug from 'debug';
11
+
12
+ const isWindows = process.platform === 'win32';
13
+
14
+ // Capture the high resolution clock at module load, so later replacements of the global
15
+ // (e.g. by fake timers in tests) don't affect timing. `performance` is available in both
16
+ // Node and browsers; fall back to `Date.now` just in case.
17
+ const perf = globalThis.performance;
18
+ /** @type {() => number} */
19
+ const now = perf && typeof perf.now === 'function' ? () => perf.now() : () => Date.now();
20
+
21
+ /**
22
+ * Start times of in-progress timings, keyed by id.
23
+ * @type {Map<string, number>}
24
+ */
25
+ let timeMarks = new Map();
26
+ /**
27
+ * Completed timings, sorted by startTime.
28
+ * @type {PerformanceEntry[]}
29
+ */
30
+ let timeEntries = [];
31
+
32
+ /**
33
+ * @param {string} id
34
+ */
35
+ function markStart(id) {
36
+ timeMarks.set(id, now());
37
+ }
38
+
39
+ /**
40
+ * @param {string} id
41
+ */
42
+ function markEnd(id) {
43
+ const endTime = now();
44
+ const startTime = timeMarks.get(id);
45
+ if (startTime === undefined) {
46
+ throw new Error(`no known mark: ${id}`);
47
+ }
48
+
49
+ const entry = /** @type {PerformanceEntry} */ ({
50
+ name: id,
51
+ entryType: 'measure',
52
+ startTime,
53
+ duration: endTime - startTime,
54
+ });
55
+
56
+ // Insert after any existing entries with the same or earlier startTime, keeping the list sorted.
57
+ let index = timeEntries.length;
58
+ while (index > 0 && timeEntries[index - 1].startTime > startTime) index--;
59
+ timeEntries.splice(index, 0, entry);
60
+ }
61
+
62
+ // @ts-expect-error: process.browser is set via bundler.
63
+ const isBrowser = Boolean(process.browser);
64
+
65
+ const colors = {
66
+ red: isBrowser ? 'crimson' : 1,
67
+ yellow: isBrowser ? 'gold' : 3,
68
+ cyan: isBrowser ? 'darkturquoise' : 6,
69
+ green: isBrowser ? 'forestgreen' : 2,
70
+ blue: isBrowser ? 'steelblue' : 4,
71
+ magenta: isBrowser ? 'palevioletred' : 5,
72
+ };
73
+
74
+ // allow non-red/yellow colors for debug()
75
+ // @ts-expect-error - `colors` is not declared in @types/debug.
76
+ debug.colors = [colors.cyan, colors.green, colors.blue, colors.magenta];
77
+
78
+ /** @typedef {{(formatter: any, ...args: any[]): void, color: string|number, enabled: boolean}} LoggerFn */
79
+
80
+ /** @extends {EventEmitter<Record<string, any[]>>} */
81
+ class Emitter extends EventEmitter {
82
+ // yarn build-types fails without this!
83
+ // https://github.com/microsoft/TypeScript/issues/41672#issuecomment-2303803072
84
+ /**
85
+ * @param {ConstructorParameters<typeof EventEmitter>[0]} [options]
86
+ */
87
+ constructor(options) {
88
+ super(options);
89
+ }
90
+
91
+ /**
92
+ * Fires off all status updates. Listen with
93
+ * `log.events.addListener('status', callback)`
94
+ * @param {string} title
95
+ * @param {Array<any>} argsArray
96
+ */
97
+ issueStatus(title, argsArray) {
98
+ if (title === 'status' || title === 'statusEnd') {
99
+ this.emit(title, [title, ...argsArray]);
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Fires off all warnings. Listen with
105
+ * `log.events.addListener('warning', callback)`
106
+ * @param {string} title
107
+ * @param {Array<any>} argsArray
108
+ */
109
+ issueWarning(title, argsArray) {
110
+ this.emit('warning', [title, ...argsArray]);
111
+ }
112
+ }
113
+
114
+ /** @type {Record<string, LoggerFn>} */
115
+ const loggersByTitle = {};
116
+ const loggingBufferColumns = 25;
117
+ /** @type {string|undefined} */
118
+ let level_;
119
+
120
+ class Log {
121
+ static events = new Emitter();
122
+
123
+ /**
124
+ * @param {string} title
125
+ * @param {Array<any>} argsArray
126
+ */
127
+ static _logToStdErr(title, argsArray) {
128
+ const log = Log.loggerfn(title);
129
+ log(argsArray[0], ...argsArray.slice(1));
130
+ }
131
+
132
+ /**
133
+ * @param {string} title
134
+ * @return {LoggerFn}
135
+ */
136
+ static loggerfn(title) {
137
+ title = `LH:${title}`;
138
+ let log = loggersByTitle[title];
139
+ if (!log) {
140
+ log = debug(title);
141
+ loggersByTitle[title] = log;
142
+ // errors with red, warnings with yellow.
143
+ if (title.endsWith('error')) {
144
+ log.color = colors.red;
145
+ } else if (title.endsWith('warn')) {
146
+ log.color = colors.yellow;
147
+ }
148
+ }
149
+ return log;
150
+ }
151
+
152
+ /**
153
+ * @param {string} level
154
+ */
155
+ static setLevel(level) {
156
+ level_ = level;
157
+ switch (level) {
158
+ case 'silent':
159
+ debug.enable('-LH:*');
160
+ break;
161
+ case 'verbose':
162
+ debug.enable('LH:*');
163
+ break;
164
+ case 'warn':
165
+ debug.enable('-LH:*, LH:*:warn, LH:*:error');
166
+ break;
167
+ case 'error':
168
+ debug.enable('-LH:*, LH:*:error');
169
+ break;
170
+ default:
171
+ debug.enable('LH:*, -LH:*:verbose');
172
+ }
173
+ }
174
+
175
+ /**
176
+ * A simple formatting utility for event logging.
177
+ * @param {string} prefix
178
+ * @param {{method?: string, params?: Record<string, any>}} data A JSON-serializable object of event data to log.
179
+ * @param {string=} level Optional logging level. Defaults to 'log'.
180
+ */
181
+ static formatProtocol(prefix, data, level) {
182
+ const columns = (!process || isBrowser) ? Infinity : process.stdout.columns;
183
+ const method = data.method || '?????';
184
+ const maxLength = columns - method.length - prefix.length - loggingBufferColumns;
185
+ // IO.read ignored here to avoid logging megabytes of trace data
186
+ const snippet = (data.params && method !== 'IO.read') ?
187
+ JSON.stringify(data.params).slice(0, maxLength) : '';
188
+ Log._logToStdErr(`${prefix}:${level || ''}`, [method, snippet]);
189
+ }
190
+
191
+ /**
192
+ * @return {boolean}
193
+ */
194
+ static isVerbose() {
195
+ return level_ === 'verbose';
196
+ }
197
+
198
+ /**
199
+ * @param {{msg: string, id: string, args?: any[]}} status
200
+ * @param {'log'|'verbose'|'warn'|'error'} [level]
201
+ */
202
+ static time({msg, id, args = []}, level = 'log') {
203
+ markStart(id);
204
+ Log[level]('status', msg, ...args);
205
+ }
206
+
207
+ /**
208
+ * @param {{msg: string, id: string, args?: any[]}} status
209
+ * @param {'log'|'verbose'|'warn'|'error'} [level]
210
+ */
211
+ static timeEnd({msg, id, args = []}, level = 'verbose') {
212
+ Log[level]('statusEnd', msg, ...args);
213
+ markEnd(id);
214
+ }
215
+
216
+ /**
217
+ * @param {string} title
218
+ * @param {...any} args
219
+ */
220
+ static log(title, ...args) {
221
+ Log.events.issueStatus(title, args);
222
+ return Log._logToStdErr(title, args);
223
+ }
224
+
225
+ /**
226
+ * @param {string} title
227
+ * @param {...any} args
228
+ */
229
+ static warn(title, ...args) {
230
+ Log.events.issueWarning(title, args);
231
+ return Log._logToStdErr(`${title}:warn`, args);
232
+ }
233
+
234
+ /**
235
+ * @param {string} title
236
+ * @param {...any} args
237
+ */
238
+ static error(title, ...args) {
239
+ return Log._logToStdErr(`${title}:error`, args);
240
+ }
241
+
242
+ /**
243
+ * @param {string} title
244
+ * @param {...any} args
245
+ */
246
+ static verbose(title, ...args) {
247
+ Log.events.issueStatus(title, args);
248
+ return Log._logToStdErr(`${title}:verbose`, args);
249
+ }
250
+
251
+ /**
252
+ * Add surrounding escape sequences to turn a string green when logged.
253
+ * @param {string} str
254
+ * @return {string}
255
+ */
256
+ static greenify(str) {
257
+ return `${Log.green}${str}${Log.reset}`;
258
+ }
259
+
260
+ /**
261
+ * Add surrounding escape sequences to turn a string red when logged.
262
+ * @param {string} str
263
+ * @return {string}
264
+ */
265
+ static redify(str) {
266
+ return `${Log.red}${str}${Log.reset}`;
267
+ }
268
+
269
+ static get green() {
270
+ return '\x1B[32m';
271
+ }
272
+
273
+ static get red() {
274
+ return '\x1B[31m';
275
+ }
276
+
277
+ static get purple() {
278
+ return '\x1b[95m';
279
+ }
280
+
281
+ static get reset() {
282
+ return '\x1B[0m';
283
+ }
284
+
285
+ static get bold() {
286
+ return '\x1b[1m';
287
+ }
288
+
289
+ static get dim() {
290
+ return '\x1b[2m';
291
+ }
292
+
293
+ static get tick() {
294
+ return isWindows ? '\u221A' : '✓';
295
+ }
296
+
297
+ static get cross() {
298
+ return isWindows ? '\u00D7' : '✘';
299
+ }
300
+
301
+ /**
302
+ * @return {PerformanceEntry[]}
303
+ */
304
+ static takeTimeEntries() {
305
+ const entries = timeEntries;
306
+ timeMarks = new Map();
307
+ timeEntries = [];
308
+ return entries;
309
+ }
310
+
311
+ /**
312
+ * @return {PerformanceEntry[]}
313
+ */
314
+ static getTimeEntries() {
315
+ return [...timeEntries];
316
+ }
317
+ }
318
+
319
+ export default Log;
@@ -5,13 +5,23 @@
5
5
  * We avoid the median of single measures like the performance score because they can still exhibit
6
6
  * outlier behavior at the beginning or end of load.
7
7
  *
8
- * @param {Array<LH.Result>} runs
9
- * @return {LH.Result}
8
+ * @template {{audits: Record<string, {numericValue?: number}>}} T
9
+ * @param {Array<T>} runs
10
+ * @return {T}
10
11
  */
11
- export function computeMedianRun(runs: Array<LH.Result>): LH.Result;
12
+ export function computeMedianRun<T extends {
13
+ audits: Record<string, {
14
+ numericValue?: number;
15
+ }>;
16
+ }>(runs: Array<T>): T;
12
17
  /**
13
- * @param {Array<LH.Result>} runs
14
- * @return {Array<LH.Result>}
18
+ * @template {{audits: Record<string, {numericValue?: number}>}} T
19
+ * @param {Array<T>} runs
20
+ * @return {Array<T>}
15
21
  */
16
- export function filterToValidRuns(runs: Array<LH.Result>): Array<LH.Result>;
22
+ export function filterToValidRuns<T extends {
23
+ audits: Record<string, {
24
+ numericValue?: number;
25
+ }>;
26
+ }>(runs: Array<T>): Array<T>;
17
27
  //# sourceMappingURL=median-run.d.ts.map
@@ -5,7 +5,11 @@
5
5
  */
6
6
 
7
7
 
8
- /** @param {LH.Result} lhr @param {string} auditName */
8
+ /**
9
+ * @template {{audits: Record<string, {numericValue?: number}>}} T
10
+ * @param {T} lhr
11
+ * @param {string} auditName
12
+ */
9
13
  const getNumericValue = (lhr, auditName) => lhr.audits[auditName]?.numericValue || NaN;
10
14
 
11
15
  /**
@@ -21,7 +25,8 @@ function getMedianValue(numbers) {
21
25
  }
22
26
 
23
27
  /**
24
- * @param {LH.Result} lhr
28
+ * @template {{audits: Record<string, {numericValue?: number}>}} T
29
+ * @param {T} lhr
25
30
  * @param {number} medianFcp
26
31
  * @param {number} medianInteractive
27
32
  */
@@ -41,8 +46,9 @@ function getMedianSortValue(lhr, medianFcp, medianInteractive) {
41
46
  * We avoid the median of single measures like the performance score because they can still exhibit
42
47
  * outlier behavior at the beginning or end of load.
43
48
  *
44
- * @param {Array<LH.Result>} runs
45
- * @return {LH.Result}
49
+ * @template {{audits: Record<string, {numericValue?: number}>}} T
50
+ * @param {Array<T>} runs
51
+ * @return {T}
46
52
  */
47
53
  function computeMedianRun(runs) {
48
54
  const missingFcp = runs.some(run =>
@@ -78,8 +84,9 @@ function computeMedianRun(runs) {
78
84
  }
79
85
 
80
86
  /**
81
- * @param {Array<LH.Result>} runs
82
- * @return {Array<LH.Result>}
87
+ * @template {{audits: Record<string, {numericValue?: number}>}} T
88
+ * @param {Array<T>} runs
89
+ * @return {Array<T>}
83
90
  */
84
91
  function filterToValidRuns(runs) {
85
92
  return runs
@@ -6,8 +6,7 @@
6
6
 
7
7
  import {EventEmitter} from 'events';
8
8
 
9
- import log from 'lighthouse-logger';
10
-
9
+ import log from './lighthouse-logger.js';
11
10
  import * as LH from '../../types/lh.js';
12
11
  import * as Lantern from './lantern/lantern.js';
13
12
  import {NetworkRequest} from './network-request.js';
@@ -73,10 +73,10 @@ export class NetworkRequest {
73
73
  static isHstsRequest(record: NetworkRequest): boolean;
74
74
  /**
75
75
  * Returns whether the network request was sent encoded.
76
- * @param {NetworkRequest} record
76
+ * @param {Pick<LH.Artifacts.NetworkRequest, 'responseHeaders'>} record
77
77
  * @return {boolean}
78
78
  */
79
- static isContentEncoded(record: NetworkRequest): boolean;
79
+ static isContentEncoded(record: Pick<LH.Artifacts.NetworkRequest, "responseHeaders">): boolean;
80
80
  /**
81
81
  * Resource size is almost always the right one to be using because of the below:
82
82
  * `transferSize = resourceSize + headers.length`.
@@ -663,7 +663,7 @@ class NetworkRequest {
663
663
 
664
664
  /**
665
665
  * Returns whether the network request was sent encoded.
666
- * @param {NetworkRequest} record
666
+ * @param {Pick<LH.Artifacts.NetworkRequest, 'responseHeaders'>} record
667
667
  * @return {boolean}
668
668
  */
669
669
  static isContentEncoded(record) {
@@ -449,7 +449,8 @@ function wrapRequestIdleCallback(cpuSlowdownMultiplier) {
449
449
  */
450
450
  function getNodeDetails(node) {
451
451
  // This bookkeeping is for the FullPageScreenshot gatherer.
452
- if (!window.__lighthouseNodesDontTouchOrAllVarianceGoesAway) {
452
+ // Pages may have overwritten this global or `Map` itself (see `_cachedNativesPreamble`).
453
+ if (!(window.__lighthouseNodesDontTouchOrAllVarianceGoesAway instanceof Map)) {
453
454
  window.__lighthouseNodesDontTouchOrAllVarianceGoesAway = new Map();
454
455
  }
455
456
 
@@ -524,9 +525,9 @@ function isBundledEnvironment() {
524
525
  const require = createRequire(import.meta.url);
525
526
 
526
527
  try {
527
- // Not foolproof, but `lighthouse-logger` is a dependency of lighthouse that should always be resolvable.
528
+ // Not foolproof, but `debug` is a dependency of lighthouse that should always be resolvable.
528
529
  // `require.resolve` will only throw in atypical/bundled environments.
529
- require.resolve('lighthouse-logger');
530
+ require.resolve('debug');
530
531
  return false;
531
532
  } catch (err) {
532
533
  return true;
@@ -1,9 +1,14 @@
1
1
  /**
2
- * @param {LH.Artifacts.NetworkRequest[]} networkRecords
3
- * @param {LH.Artifacts.Script} script
4
- * @return {LH.Artifacts.NetworkRequest|undefined}
2
+ * @template {{url: string, frameId?: string, redirectDestination?: T}} T
3
+ * @param {T[]} networkRecords
4
+ * @param {Pick<LH.Artifacts.Script, 'url'|'executionContextAuxData'>} script
5
+ * @return {T|undefined}
5
6
  */
6
- export function getRequestForScript(networkRecords: LH.Artifacts.NetworkRequest[], script: LH.Artifacts.Script): LH.Artifacts.NetworkRequest | undefined;
7
+ export function getRequestForScript<T extends {
8
+ url: string;
9
+ frameId?: string;
10
+ redirectDestination?: T;
11
+ }>(networkRecords: T[], script: Pick<LH.Artifacts.Script, "url" | "executionContextAuxData">): T | undefined;
7
12
  /**
8
13
  * @param {LH.Artifacts.Script} script
9
14
  * @return {boolean}
@@ -16,22 +21,32 @@ export function isInline(script: LH.Artifacts.Script): boolean;
16
21
  *
17
22
  * This differs from `estimateTransferSize` only in that is subtracts the response headers from the estimate.
18
23
  *
19
- * @param {LH.Artifacts.NetworkRequest|undefined} networkRecord
24
+ * @param {{resourceType?: LH.Crdp.Network.ResourceType, transferSize?: number, resourceSize?: number, responseHeaders: LH.Artifacts.NetworkRequest['responseHeaders'], responseHeadersTransferSize?: number}|undefined} networkRecord
20
25
  * @param {number} totalBytes Uncompressed size of the resource
21
26
  * @param {LH.Crdp.Network.ResourceType=} resourceType
22
27
  * @return {number}
23
28
  */
24
- export function estimateCompressedContentSize(networkRecord: LH.Artifacts.NetworkRequest | undefined, totalBytes: number, resourceType?: LH.Crdp.Network.ResourceType | undefined): number;
29
+ export function estimateCompressedContentSize(networkRecord: {
30
+ resourceType?: LH.Crdp.Network.ResourceType;
31
+ transferSize?: number;
32
+ resourceSize?: number;
33
+ responseHeaders: LH.Artifacts.NetworkRequest["responseHeaders"];
34
+ responseHeadersTransferSize?: number;
35
+ } | undefined, totalBytes: number, resourceType?: LH.Crdp.Network.ResourceType | undefined): number;
25
36
  /**
26
37
  * Estimates the number of bytes this network record would have consumed on the network based on the
27
38
  * uncompressed size (totalBytes). Uses the actual transfer size from the network record if applicable.
28
39
  *
29
- * @param {LH.Artifacts.NetworkRequest|undefined} networkRecord
40
+ * @param {{resourceType?: LH.Crdp.Network.ResourceType, transferSize?: number, resourceSize?: number}|undefined} networkRecord
30
41
  * @param {number} totalBytes Uncompressed size of the resource
31
42
  * @param {LH.Crdp.Network.ResourceType=} resourceType
32
43
  * @return {number}
33
44
  */
34
- export function estimateTransferSize(networkRecord: LH.Artifacts.NetworkRequest | undefined, totalBytes: number, resourceType?: LH.Crdp.Network.ResourceType | undefined): number;
45
+ export function estimateTransferSize(networkRecord: {
46
+ resourceType?: LH.Crdp.Network.ResourceType;
47
+ transferSize?: number;
48
+ resourceSize?: number;
49
+ } | undefined, totalBytes: number, resourceType?: LH.Crdp.Network.ResourceType | undefined): number;
35
50
  /**
36
51
  * Utility function to estimate the ratio of the compression on the resource.
37
52
  * This excludes the size of the response headers.
@@ -15,9 +15,10 @@ function isInline(script) {
15
15
  }
16
16
 
17
17
  /**
18
- * @param {LH.Artifacts.NetworkRequest[]} networkRecords
19
- * @param {LH.Artifacts.Script} script
20
- * @return {LH.Artifacts.NetworkRequest|undefined}
18
+ * @template {{url: string, frameId?: string, redirectDestination?: T}} T
19
+ * @param {T[]} networkRecords
20
+ * @param {Pick<LH.Artifacts.Script, 'url'|'executionContextAuxData'>} script
21
+ * @return {T|undefined}
21
22
  */
22
23
  function getRequestForScript(networkRecords, script) {
23
24
  const frameId = script.executionContextAuxData?.frameId;
@@ -43,7 +44,7 @@ function getRequestForScript(networkRecords, script) {
43
44
  * Estimates the number of bytes this network record would have consumed on the network based on the
44
45
  * uncompressed size (totalBytes). Uses the actual transfer size from the network record if applicable.
45
46
  *
46
- * @param {LH.Artifacts.NetworkRequest|undefined} networkRecord
47
+ * @param {{resourceType?: LH.Crdp.Network.ResourceType, transferSize?: number, resourceSize?: number}|undefined} networkRecord
47
48
  * @param {number} totalBytes Uncompressed size of the resource
48
49
  * @param {LH.Crdp.Network.ResourceType=} resourceType
49
50
  * @return {number}
@@ -88,7 +89,7 @@ function estimateTransferSize(networkRecord, totalBytes, resourceType) {
88
89
  *
89
90
  * This differs from `estimateTransferSize` only in that is subtracts the response headers from the estimate.
90
91
  *
91
- * @param {LH.Artifacts.NetworkRequest|undefined} networkRecord
92
+ * @param {{resourceType?: LH.Crdp.Network.ResourceType, transferSize?: number, resourceSize?: number, responseHeaders: LH.Artifacts.NetworkRequest['responseHeaders'], responseHeadersTransferSize?: number}|undefined} networkRecord
92
93
  * @param {number} totalBytes Uncompressed size of the resource
93
94
  * @param {LH.Crdp.Network.ResourceType=} resourceType
94
95
  * @return {number}
@@ -119,7 +120,7 @@ function estimateCompressedContentSize(networkRecord, totalBytes, resourceType)
119
120
  // This is not encoded, so we can use resourceSize directly.
120
121
  // This would be equivalent to transfer size minus headers transfer size, but transfer size
121
122
  // may also include bytes for SSL connection etc.
122
- contentTransferSize = networkRecord.resourceSize;
123
+ contentTransferSize = networkRecord.resourceSize || 0;
123
124
  } else if (networkRecord.responseHeadersTransferSize) {
124
125
  // Subtract the size of the encoded headers.
125
126
  contentTransferSize =