lighthouse 12.0.0-dev.20240609 → 12.0.0-dev.20240611

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 (45) hide show
  1. package/core/audits/long-tasks.d.ts +7 -6
  2. package/core/audits/long-tasks.js +5 -4
  3. package/core/computed/metrics/lantern-metric.js +2 -2
  4. package/core/computed/metrics/lantern-speed-index.js +1 -1
  5. package/core/computed/metrics/total-blocking-time.js +1 -1
  6. package/core/computed/navigation-insights.d.ts +2 -22
  7. package/core/computed/page-dependency-graph.js +5 -2
  8. package/core/computed/processed-navigation.d.ts +1 -1
  9. package/core/computed/tbt-impact-tasks.js +3 -2
  10. package/core/computed/trace-engine-result.d.ts +0 -12
  11. package/core/computed/trace-engine-result.js +5 -20
  12. package/core/config/constants.d.ts +28 -53
  13. package/core/config/constants.js +2 -43
  14. package/core/gather/driver/target-manager.d.ts +1 -1
  15. package/core/gather/gatherers/root-causes.js +0 -1
  16. package/core/gather/session.d.ts +3 -3
  17. package/core/lib/lantern/cpu-node.d.ts +10 -10
  18. package/core/lib/lantern/cpu-node.js +5 -5
  19. package/core/lib/lantern/lantern.d.ts +48 -11
  20. package/core/lib/lantern/lantern.js +40 -43
  21. package/core/lib/lantern/metric.d.ts +10 -12
  22. package/core/lib/lantern/metric.js +7 -7
  23. package/core/lib/lantern/metrics/interactive.d.ts +3 -8
  24. package/core/lib/lantern/metrics/interactive.js +5 -5
  25. package/core/lib/lantern/metrics/largest-contentful-paint.d.ts +4 -3
  26. package/core/lib/lantern/metrics/largest-contentful-paint.js +4 -4
  27. package/core/lib/lantern/metrics/max-potential-fid.d.ts +3 -8
  28. package/core/lib/lantern/metrics/max-potential-fid.js +5 -5
  29. package/core/lib/lantern/metrics/speed-index.d.ts +3 -8
  30. package/core/lib/lantern/metrics/speed-index.js +8 -8
  31. package/core/lib/lantern/metrics/total-blocking-time.d.ts +3 -8
  32. package/core/lib/lantern/metrics/total-blocking-time.js +6 -6
  33. package/core/lib/lantern/page-dependency-graph.d.ts +17 -49
  34. package/core/lib/lantern/page-dependency-graph.js +45 -354
  35. package/core/lib/lantern/simulator/network-analyzer.d.ts +6 -6
  36. package/core/lib/lantern/simulator/network-analyzer.js +2 -2
  37. package/core/lib/lantern/simulator/simulator.js +6 -6
  38. package/core/lib/lantern/trace-engine-computation-data.d.ts +25 -0
  39. package/core/lib/lantern/trace-engine-computation-data.js +468 -0
  40. package/core/lib/lantern/types/lantern.d.ts +77 -5
  41. package/core/lib/lantern-trace-saver.js +1 -1
  42. package/package.json +8 -8
  43. package/types/artifacts.d.ts +4 -11
  44. /package/core/{computed/metrics → lib/lantern}/tbt-utils.d.ts +0 -0
  45. /package/core/{computed/metrics → lib/lantern}/tbt-utils.js +0 -0
@@ -0,0 +1,468 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import * as TraceEngine from '@paulirish/trace_engine';
8
+ import * as Protocol from '@paulirish/trace_engine/generated/protocol.js';
9
+
10
+ import * as Lantern from './types/lantern.js';
11
+ import {PageDependencyGraph} from './page-dependency-graph.js';
12
+ import {RESOURCE_TYPES} from '../network-request.js';
13
+
14
+ /** @typedef {import('@paulirish/trace_engine/models/trace/handlers/PageLoadMetricsHandler.js').MetricName} MetricName */
15
+ /** @typedef {import('@paulirish/trace_engine/models/trace/handlers/PageLoadMetricsHandler.js').MetricScore} MetricScore */
16
+
17
+ /**
18
+ * @param {TraceEngine.Handlers.Types.TraceParseData} traceEngineData
19
+ * @return {Lantern.Simulation.ProcessedNavigation}
20
+ */
21
+ function createProcessedNavigation(traceEngineData) {
22
+ const Meta = traceEngineData.Meta;
23
+ const frameId = Meta.mainFrameId;
24
+ const scoresByNav = traceEngineData.PageLoadMetrics.metricScoresByFrameId.get(frameId);
25
+ if (!scoresByNav) {
26
+ throw new Error('missing metric scores for main frame');
27
+ }
28
+
29
+ const lastNavigationId = Meta.mainFrameNavigations.at(-1)?.args.data?.navigationId;
30
+ const scores = lastNavigationId && scoresByNav.get(lastNavigationId);
31
+ if (!scores) {
32
+ throw new Error('missing metric scores for specified navigation');
33
+ }
34
+
35
+ /** @param {MetricName} metric */
36
+ const getTimestampOrUndefined = metric => {
37
+ const metricScore = scores.get(metric);
38
+ if (!metricScore?.event) return;
39
+ return metricScore.event.ts;
40
+ };
41
+ /** @param {MetricName} metric */
42
+ const getTimestamp = metric => {
43
+ const metricScore = scores.get(metric);
44
+ if (!metricScore?.event) throw new Error(`missing metric: ${metric}`);
45
+ return metricScore.event.ts;
46
+ };
47
+ // TODO: should use `MetricName.LCP`, but it is a const enum.
48
+ const FCP = /** @type {MetricName} */('FCP');
49
+ const LCP = /** @type {MetricName} */('LCP');
50
+ return {
51
+ timestamps: {
52
+ firstContentfulPaint: getTimestamp(FCP),
53
+ largestContentfulPaint: getTimestampOrUndefined(LCP),
54
+ },
55
+ };
56
+ }
57
+
58
+ /**
59
+ * @param {URL|string} url
60
+ */
61
+ function createParsedUrl(url) {
62
+ if (typeof url === 'string') {
63
+ url = new URL(url);
64
+ }
65
+ return {
66
+ scheme: url.protocol.split(':')[0],
67
+ // Intentional, DevTools uses different terminology
68
+ host: url.hostname,
69
+ securityOrigin: url.origin,
70
+ };
71
+ }
72
+
73
+ /**
74
+ * Returns a map of `pid` -> `tid[]`.
75
+ * @param {Lantern.Trace} trace
76
+ * @return {Map<number, number[]>}
77
+ */
78
+ function findWorkerThreads(trace) {
79
+ // TODO: WorkersHandler in TraceEngine needs to be updated to also include `pid` (only had `tid`).
80
+ const workerThreads = new Map();
81
+ const workerCreationEvents = ['ServiceWorker thread', 'DedicatedWorker thread'];
82
+
83
+ for (const event of trace.traceEvents) {
84
+ if (event.name !== 'thread_name' || !event.args.name) {
85
+ continue;
86
+ }
87
+ if (!workerCreationEvents.includes(event.args.name)) {
88
+ continue;
89
+ }
90
+
91
+ const tids = workerThreads.get(event.pid);
92
+ if (tids) {
93
+ tids.push(event.tid);
94
+ } else {
95
+ workerThreads.set(event.pid, [event.tid]);
96
+ }
97
+ }
98
+
99
+ return workerThreads;
100
+ }
101
+
102
+ /**
103
+ * @param {TraceEngine.Handlers.Types.TraceParseData} traceEngineData
104
+ * @param {Map<number, number[]>} workerThreads
105
+ * @param {import('@paulirish/trace_engine/models/trace/types/TraceEvents.js').SyntheticNetworkRequest} request
106
+ * @return {Lantern.NetworkRequest=}
107
+ */
108
+ function createLanternRequest(traceEngineData, workerThreads, request) {
109
+ if (request.args.data.connectionId === undefined ||
110
+ request.args.data.connectionReused === undefined) {
111
+ throw new Error('Trace is too old');
112
+ }
113
+
114
+ let url;
115
+ try {
116
+ url = new URL(request.args.data.url);
117
+ } catch (e) {
118
+ return;
119
+ }
120
+
121
+ const timing = request.args.data.timing ? {
122
+ // These two timings are not included in the trace.
123
+ workerFetchStart: -1,
124
+ workerRespondWithSettled: -1,
125
+ ...request.args.data.timing,
126
+ } : undefined;
127
+
128
+ const networkRequestTime = timing ?
129
+ timing.requestTime * 1000 :
130
+ request.args.data.syntheticData.downloadStart / 1000;
131
+
132
+ let fromWorker = false;
133
+ const tids = workerThreads.get(request.pid);
134
+ if (tids?.includes(request.tid)) {
135
+ fromWorker = true;
136
+ }
137
+
138
+ // TraceEngine collects worker thread ids in a different manner than `workerThreads` does.
139
+ // AFAIK these should be equivalent, but in case they are not let's also check this for now.
140
+ if (traceEngineData.Workers.workerIdByThread.has(request.tid)) {
141
+ fromWorker = true;
142
+ }
143
+
144
+ // typescript const enums.... gotta stop using those ...
145
+ const Other = /** @type {Protocol.Network.InitiatorType.Other} */ ('other');
146
+
147
+ // `initiator` in the trace does not contain the stack trace for JS-initiated
148
+ // requests. Instead, that is stored in the `stackTrace` property of the SyntheticNetworkRequest.
149
+ // There are some minor differences in the fields, accounted for here.
150
+ // Most importantly, there seems to be fewer frames in the trace than the equivalent
151
+ // events over the CDP. This results in less accuracy in determining the initiator request,
152
+ // which means less edges in the graph, which mean worse results.
153
+ // TODO: Should fix in Chromium.
154
+ /** @type {Lantern.NetworkRequest['initiator']} */
155
+ const initiator = request.args.data.initiator ?? {type: Other};
156
+ if (request.args.data.stackTrace) {
157
+ const callFrames = request.args.data.stackTrace.map(f => {
158
+ return {
159
+ scriptId: /** @type {Protocol.Runtime.ScriptId} */(String(f.scriptId)),
160
+ url: f.url,
161
+ lineNumber: f.lineNumber - 1,
162
+ columnNumber: f.columnNumber - 1,
163
+ functionName: f.functionName,
164
+ };
165
+ });
166
+ initiator.stack = {callFrames};
167
+ // Note: there is no `parent` to set ...
168
+ }
169
+
170
+ let resourceType = request.args.data.resourceType;
171
+ if (request.args.data.initiator?.fetchType === 'xmlhttprequest') {
172
+ // @ts-expect-error yes XHR is a valid ResourceType. TypeScript const enums are so unhelpful.
173
+ resourceType = 'XHR';
174
+ } else if (request.args.data.initiator?.fetchType === 'fetch') {
175
+ // @ts-expect-error yes Fetch is a valid ResourceType. TypeScript const enums are so unhelpful.
176
+ resourceType = 'Fetch';
177
+ }
178
+
179
+ // TODO: set decodedBodyLength for data urls in Trace Engine.
180
+ let resourceSize = request.args.data.decodedBodyLength ?? 0;
181
+ if (url.protocol === 'data:' && resourceSize === 0) {
182
+ const needle = 'base64,';
183
+ const index = url.pathname.indexOf(needle);
184
+ if (index !== -1) {
185
+ resourceSize = atob(url.pathname.substring(index + needle.length)).length;
186
+ }
187
+ }
188
+
189
+ return {
190
+ rawRequest: request,
191
+ requestId: request.args.data.requestId,
192
+ connectionId: request.args.data.connectionId,
193
+ connectionReused: request.args.data.connectionReused,
194
+ url: request.args.data.url,
195
+ protocol: request.args.data.protocol,
196
+ parsedURL: createParsedUrl(url),
197
+ documentURL: request.args.data.requestingFrameUrl,
198
+ rendererStartTime: request.ts / 1000,
199
+ networkRequestTime,
200
+ responseHeadersEndTime: request.args.data.syntheticData.downloadStart / 1000,
201
+ networkEndTime: request.args.data.syntheticData.finishTime / 1000,
202
+ transferSize: request.args.data.encodedDataLength,
203
+ resourceSize,
204
+ fromDiskCache: request.args.data.syntheticData.isDiskCached,
205
+ fromMemoryCache: request.args.data.syntheticData.isMemoryCached,
206
+ isLinkPreload: request.args.data.isLinkPreload,
207
+ finished: request.args.data.finished,
208
+ failed: request.args.data.failed,
209
+ statusCode: request.args.data.statusCode,
210
+ initiator,
211
+ timing,
212
+ resourceType,
213
+ mimeType: request.args.data.mimeType,
214
+ priority: request.args.data.priority,
215
+ frameId: request.args.data.frame,
216
+ fromWorker,
217
+ // Set later.
218
+ redirects: undefined,
219
+ redirectSource: undefined,
220
+ redirectDestination: undefined,
221
+ initiatorRequest: undefined,
222
+ };
223
+ }
224
+
225
+ /**
226
+ * @param {Lantern.NetworkRequest} request The request to find the initiator of
227
+ * @param {Map<string, Lantern.NetworkRequest[]>} requestsByURL
228
+ * @return {Lantern.NetworkRequest|null}
229
+ */
230
+ function chooseInitiatorRequest(request, requestsByURL) {
231
+ if (request.redirectSource) {
232
+ return request.redirectSource;
233
+ }
234
+
235
+ const initiatorURL = PageDependencyGraph.getNetworkInitiators(request)[0];
236
+ let candidates = requestsByURL.get(initiatorURL) || [];
237
+ // The (valid) initiator must come before the initiated request.
238
+ candidates = candidates.filter(c => {
239
+ return c.responseHeadersEndTime <= request.rendererStartTime &&
240
+ c.finished && !c.failed;
241
+ });
242
+ if (candidates.length > 1) {
243
+ // Disambiguate based on prefetch. Prefetch requests have type 'Other' and cannot
244
+ // initiate requests, so we drop them here.
245
+ const nonPrefetchCandidates = candidates.filter(
246
+ cand => cand.resourceType !== RESOURCE_TYPES.Other);
247
+ if (nonPrefetchCandidates.length) {
248
+ candidates = nonPrefetchCandidates;
249
+ }
250
+ }
251
+ if (candidates.length > 1) {
252
+ // Disambiguate based on frame. It's likely that the initiator comes from the same frame.
253
+ const sameFrameCandidates = candidates.filter(cand => cand.frameId === request.frameId);
254
+ if (sameFrameCandidates.length) {
255
+ candidates = sameFrameCandidates;
256
+ }
257
+ }
258
+ if (candidates.length > 1 && request.initiator.type === 'parser') {
259
+ // Filter to just Documents when initiator type is parser.
260
+ const documentCandidates = candidates.filter(cand =>
261
+ cand.resourceType === RESOURCE_TYPES.Document);
262
+ if (documentCandidates.length) {
263
+ candidates = documentCandidates;
264
+ }
265
+ }
266
+ if (candidates.length > 1) {
267
+ // If all real loads came from successful preloads (url preloaded and
268
+ // loads came from the cache), filter to link rel=preload request(s).
269
+ const linkPreloadCandidates = candidates.filter(c => c.isLinkPreload);
270
+ if (linkPreloadCandidates.length) {
271
+ const nonPreloadCandidates = candidates.filter(c => !c.isLinkPreload);
272
+ const allPreloaded = nonPreloadCandidates.every(c => c.fromDiskCache || c.fromMemoryCache);
273
+ if (nonPreloadCandidates.length && allPreloaded) {
274
+ candidates = linkPreloadCandidates;
275
+ }
276
+ }
277
+ }
278
+
279
+ // Only return an initiator if the result is unambiguous.
280
+ return candidates.length === 1 ? candidates[0] : null;
281
+ }
282
+
283
+ /**
284
+ * @param {Lantern.NetworkRequest[]} lanternRequests
285
+ */
286
+ function linkInitiators(lanternRequests) {
287
+ /** @type {Map<string, Lantern.NetworkRequest[]>} */
288
+ const requestsByURL = new Map();
289
+ for (const request of lanternRequests) {
290
+ const requests = requestsByURL.get(request.url) || [];
291
+ requests.push(request);
292
+ requestsByURL.set(request.url, requests);
293
+ }
294
+
295
+ for (const request of lanternRequests) {
296
+ const initiatorRequest = chooseInitiatorRequest(request, requestsByURL);
297
+ if (initiatorRequest) {
298
+ request.initiatorRequest = initiatorRequest;
299
+ }
300
+ }
301
+ }
302
+
303
+ /**
304
+ * @param {Lantern.Trace} trace
305
+ * @param {TraceEngine.Handlers.Types.TraceParseData} traceEngineData
306
+ * @return {Lantern.NetworkRequest[]}
307
+ */
308
+ function createNetworkRequests(trace, traceEngineData) {
309
+ const workerThreads = findWorkerThreads(trace);
310
+
311
+ /** @type {Lantern.NetworkRequest[]} */
312
+ const lanternRequests = [];
313
+ for (const request of traceEngineData.NetworkRequests.byTime) {
314
+ const lanternRequest = createLanternRequest(traceEngineData, workerThreads, request);
315
+ if (lanternRequest) {
316
+ lanternRequests.push(lanternRequest);
317
+ }
318
+ }
319
+
320
+ // TraceEngine consolidates all redirects into a single request object, but lantern needs
321
+ // an entry for each redirected request.
322
+ for (const request of [...lanternRequests]) {
323
+ if (!request.rawRequest) continue;
324
+
325
+ const redirects = request.rawRequest.args.data.redirects;
326
+ if (!redirects.length) continue;
327
+
328
+ const requestChain = [];
329
+ for (const redirect of redirects) {
330
+ const redirectedRequest = structuredClone(request);
331
+
332
+ redirectedRequest.networkRequestTime = redirect.ts / 1000;
333
+ redirectedRequest.rendererStartTime = redirectedRequest.networkRequestTime;
334
+
335
+ redirectedRequest.networkEndTime = (redirect.ts + redirect.dur) / 1000;
336
+ redirectedRequest.responseHeadersEndTime = redirectedRequest.networkEndTime;
337
+
338
+ redirectedRequest.timing = {
339
+ requestTime: redirectedRequest.networkRequestTime / 1000,
340
+ receiveHeadersStart: redirectedRequest.responseHeadersEndTime,
341
+ receiveHeadersEnd: redirectedRequest.responseHeadersEndTime,
342
+ proxyStart: -1,
343
+ proxyEnd: -1,
344
+ dnsStart: -1,
345
+ dnsEnd: -1,
346
+ connectStart: -1,
347
+ connectEnd: -1,
348
+ sslStart: -1,
349
+ sslEnd: -1,
350
+ sendStart: -1,
351
+ sendEnd: -1,
352
+ workerStart: -1,
353
+ workerReady: -1,
354
+ workerFetchStart: -1,
355
+ workerRespondWithSettled: -1,
356
+ pushStart: -1,
357
+ pushEnd: -1,
358
+ };
359
+
360
+ redirectedRequest.url = redirect.url;
361
+ redirectedRequest.parsedURL = createParsedUrl(redirect.url);
362
+ // TODO: TraceEngine is not retaining the actual status code.
363
+ redirectedRequest.statusCode = 302;
364
+ redirectedRequest.resourceType = undefined;
365
+ // TODO: TraceEngine is not retaining transfer size of redirected request.
366
+ redirectedRequest.transferSize = 400;
367
+ requestChain.push(redirectedRequest);
368
+ lanternRequests.push(redirectedRequest);
369
+ }
370
+ requestChain.push(request);
371
+
372
+ for (let i = 0; i < requestChain.length; i++) {
373
+ const request = requestChain[i];
374
+ if (i > 0) {
375
+ request.redirectSource = requestChain[i - 1];
376
+ request.redirects = requestChain.slice(0, i);
377
+ }
378
+ if (i !== requestChain.length - 1) {
379
+ request.redirectDestination = requestChain[i + 1];
380
+ }
381
+ }
382
+
383
+ // Apply the `:redirect` requestId convention: only redirects[0].requestId is the actual
384
+ // requestId, all the rest have n occurences of `:redirect` as a suffix.
385
+ for (let i = 1; i < requestChain.length; i++) {
386
+ requestChain[i].requestId = `${requestChain[i - 1].requestId}:redirect`;
387
+ }
388
+ }
389
+
390
+ linkInitiators(lanternRequests);
391
+
392
+ // This would already be sorted by rendererStartTime, if not for the redirect unwrapping done
393
+ // above.
394
+ return lanternRequests.sort((a, b) => a.rendererStartTime - b.rendererStartTime);
395
+ }
396
+
397
+ /**
398
+ * @param {Lantern.Trace} trace
399
+ * @param {TraceEngine.Handlers.Types.TraceParseData} traceEngineData
400
+ * @return {Lantern.TraceEvent[]}
401
+ */
402
+ function collectMainThreadEvents(trace, traceEngineData) {
403
+ const Meta = traceEngineData.Meta;
404
+ const mainFramePids = Meta.mainFrameNavigations.length
405
+ ? new Set(Meta.mainFrameNavigations.map(nav => nav.pid))
406
+ : Meta.topLevelRendererIds;
407
+
408
+ const rendererPidToTid = new Map();
409
+ for (const pid of mainFramePids) {
410
+ const threads = Meta.threadsInProcess.get(pid) ?? [];
411
+
412
+ let found = false;
413
+ for (const [tid, thread] of threads) {
414
+ if (thread.args.name === 'CrRendererMain') {
415
+ rendererPidToTid.set(pid, tid);
416
+ found = true;
417
+ break;
418
+ }
419
+ }
420
+
421
+ if (found) continue;
422
+
423
+ // `CrRendererMain` can be missing if chrome is launched with the `--single-process` flag.
424
+ // In this case, page tasks will be run in the browser thread.
425
+ for (const [tid, thread] of threads) {
426
+ if (thread.args.name === 'CrBrowserMain') {
427
+ rendererPidToTid.set(pid, tid);
428
+ found = true;
429
+ break;
430
+ }
431
+ }
432
+ }
433
+
434
+ return trace.traceEvents.filter(e => rendererPidToTid.get(e.pid) === e.tid);
435
+ }
436
+
437
+ /**
438
+ * @param {Lantern.NetworkRequest[]} requests
439
+ * @param {Lantern.Trace} trace
440
+ * @param {TraceEngine.Handlers.Types.TraceParseData} traceEngineData
441
+ * @param {Lantern.Simulation.URL=} URL
442
+ */
443
+ function createGraph(requests, trace, traceEngineData, URL) {
444
+ const mainThreadEvents = collectMainThreadEvents(trace, traceEngineData);
445
+
446
+ // URL defines the initial request that the Lantern graph starts at (the root node) and the
447
+ // main document request. These are equal if there are no redirects.
448
+ if (!URL) {
449
+ URL = {
450
+ requestedUrl: requests[0].url,
451
+ mainDocumentUrl: '',
452
+ };
453
+
454
+ let request = requests[0];
455
+ while (request.redirectDestination) {
456
+ request = request.redirectDestination;
457
+ }
458
+ URL.mainDocumentUrl = request.url;
459
+ }
460
+
461
+ return PageDependencyGraph.createGraph(mainThreadEvents, requests, URL);
462
+ }
463
+
464
+ export {
465
+ createProcessedNavigation,
466
+ createNetworkRequests,
467
+ createGraph,
468
+ };
@@ -4,7 +4,58 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import * as LH from '../../../../types/lh.js';
7
+ import * as Protocol from '@paulirish/trace_engine/generated/protocol.js';
8
+
9
+ declare module Util {
10
+ /** An object with the keys in the union K mapped to themselves as values. */
11
+ type SelfMap<K extends string> = {
12
+ [P in K]: P;
13
+ };
14
+ }
15
+
16
+ type TraceEvent = {
17
+ name: string;
18
+ cat: string;
19
+ args: {
20
+ name?: string;
21
+ fileName?: string;
22
+ snapshot?: string;
23
+ sync_id?: string;
24
+ beginData?: {
25
+ frame?: string;
26
+ startLine?: number;
27
+ url?: string;
28
+ };
29
+ data?: {
30
+ frame?: string;
31
+ readyState?: number;
32
+ stackTrace?: {
33
+ url: string
34
+ }[];
35
+ url?: string;
36
+ };
37
+ };
38
+ pid: number;
39
+ tid: number;
40
+ /** Timestamp of the event in microseconds. */
41
+ ts: number;
42
+ dur: number;
43
+ }
44
+ type Trace = {traceEvents: TraceEvent[]};
45
+ type ResourcePriority = ('VeryLow' | 'Low' | 'Medium' | 'High' | 'VeryHigh');
46
+ type ResourceType = ('Document' | 'Stylesheet' | 'Image' | 'Media' | 'Font' | 'Script' | 'TextTrack' | 'XHR' | 'Fetch' | 'Prefetch' | 'EventSource' | 'WebSocket' | 'Manifest' | 'SignedExchange' | 'Ping' | 'CSPViolationReport' | 'Preflight' | 'Other');
47
+ type InitiatorType = ('parser' | 'script' | 'preload' | 'SignedExchange' | 'preflight' | 'other');
48
+ type ResourceTiming = Protocol.Network.ResourceTiming;
49
+ type CallStack = {
50
+ callFrames: Array<{
51
+ scriptId: string;
52
+ url: string;
53
+ lineNumber: number;
54
+ columnNumber: number;
55
+ functionName: string;
56
+ }>;
57
+ parent?: CallStack;
58
+ }
8
59
 
9
60
  type ParsedURL = {
10
61
  /**
@@ -80,24 +131,45 @@ export class NetworkRequest<T = any> {
80
131
  redirectSource: NetworkRequest<T> | undefined;
81
132
  /** The network request that this one redirected to */
82
133
  redirectDestination: NetworkRequest<T> | undefined;
83
- initiator: LH.Crdp.Network.Initiator;
134
+ // TODO: can't use Protocol.Network.Initiator because of type mismatch in Lighthouse initiator.
135
+ initiator: {
136
+ type: InitiatorType;
137
+ url?: string;
138
+ stack?: CallStack;
139
+ };
84
140
  initiatorRequest: NetworkRequest<T> | undefined;
85
141
  /** The chain of network requests that redirected to this one */
86
142
  redirects: NetworkRequest[] | undefined;
87
- timing: LH.Crdp.Network.ResourceTiming | undefined;
143
+ timing: Protocol.Network.ResourceTiming | undefined;
88
144
  /**
89
145
  * Optional value for how long the server took to respond to this request.
90
146
  * When not provided, the server response time is derived from the timing object.
91
147
  */
92
148
  serverResponseTime?: number;
93
- resourceType: LH.Crdp.Network.ResourceType | undefined;
149
+ resourceType: ResourceType | undefined;
94
150
  mimeType: string;
95
- priority: LH.Crdp.Network.ResourcePriority;
151
+ priority: ResourcePriority;
96
152
  frameId: string | undefined;
97
153
  fromWorker: boolean;
98
154
  }
99
155
 
156
+ interface Metric<T = any> {
157
+ timing: number;
158
+ timestamp?: never;
159
+ optimisticEstimate: Simulation.Result<T>;
160
+ pessimisticEstimate: Simulation.Result<T>;
161
+ optimisticGraph: Simulation.GraphNode<T>;
162
+ pessimisticGraph: Simulation.GraphNode<T>;
163
+ }
164
+
100
165
  export namespace Simulation {
166
+ type URL = {
167
+ /** URL of the initially requested URL */
168
+ requestedUrl?: string;
169
+ /** URL of the last document request */
170
+ mainDocumentUrl?: string;
171
+ };
172
+
101
173
  type GraphNode<T> = import('../base-node.js').Node<T>;
102
174
  type GraphNetworkNode<T> = import('../network-node.js').NetworkNode<T>;
103
175
  type GraphCPUNode = import('../cpu-node.js').CPUNode;
@@ -116,7 +116,7 @@ function convertNodeTimingsToTrace(nodeTimings) {
116
116
  const ts = eventTs + (event.ts - nestedBaseTs) * multiplier;
117
117
  const newEvent = {...event, ...{pid: baseEvent.pid, tid: baseEvent.tid}, ts};
118
118
  if (event.dur) newEvent.dur = event.dur * multiplier;
119
- events.push(newEvent);
119
+ events.push(/** @type {LH.TraceEvent} */(newEvent));
120
120
  }
121
121
 
122
122
  return events;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lighthouse",
3
3
  "type": "module",
4
- "version": "12.0.0-dev.20240609",
4
+ "version": "12.0.0-dev.20240611",
5
5
  "description": "Automated auditing, performance metrics, and best practices for the web.",
6
6
  "main": "./core/index.js",
7
7
  "bin": {
@@ -167,7 +167,7 @@
167
167
  "pako": "^2.0.3",
168
168
  "preact": "^10.7.2",
169
169
  "pretty-json-stringify": "^0.0.2",
170
- "puppeteer": "^22.6.5",
170
+ "puppeteer": "^22.10.0",
171
171
  "resolve": "^1.22.1",
172
172
  "rollup": "^2.52.7",
173
173
  "rollup-plugin-polyfill-node": "^0.12.0",
@@ -183,11 +183,11 @@
183
183
  "dependencies": {
184
184
  "@paulirish/trace_engine": "^0.0.23",
185
185
  "@sentry/node": "^6.17.4",
186
- "axe-core": "^4.9.0",
186
+ "axe-core": "^4.9.1",
187
187
  "chrome-launcher": "^1.1.1",
188
188
  "configstore": "^5.0.1",
189
189
  "csp_evaluator": "1.1.1",
190
- "devtools-protocol": "0.0.1299070",
190
+ "devtools-protocol": "0.0.1312386",
191
191
  "enquirer": "^2.3.6",
192
192
  "http-link-header": "^1.1.1",
193
193
  "intl-messageformat": "^10.5.3",
@@ -200,19 +200,19 @@
200
200
  "metaviewport-parser": "0.3.0",
201
201
  "open": "^8.4.0",
202
202
  "parse-cache-control": "1.0.1",
203
- "puppeteer-core": "^22.6.5",
203
+ "puppeteer-core": "^22.10.0",
204
204
  "robots-parser": "^3.0.1",
205
205
  "semver": "^5.3.0",
206
206
  "speedline-core": "^1.4.3",
207
- "third-party-web": "^0.24.2",
207
+ "third-party-web": "^0.24.3",
208
208
  "tldts-icann": "^6.1.16",
209
209
  "ws": "^7.0.0",
210
210
  "yargs": "^17.3.1",
211
211
  "yargs-parser": "^21.0.0"
212
212
  },
213
213
  "resolutions": {
214
- "puppeteer/**/devtools-protocol": "0.0.1299070",
215
- "puppeteer-core/**/devtools-protocol": "0.0.1299070"
214
+ "puppeteer/**/devtools-protocol": "0.0.1312386",
215
+ "puppeteer-core/**/devtools-protocol": "0.0.1312386"
216
216
  },
217
217
  "repository": "GoogleChrome/lighthouse",
218
218
  "keywords": [
@@ -6,6 +6,7 @@
6
6
 
7
7
  import {Protocol as Crdp} from 'devtools-protocol/types/protocol.js';
8
8
  import * as TraceEngine from '@paulirish/trace_engine';
9
+ import * as Lantern from '../core/lib/lantern/types/lantern.js';
9
10
  import {LayoutShiftRootCausesData} from '@paulirish/trace_engine/models/trace/root-causes/LayoutShift.js';
10
11
 
11
12
  import {parseManifest} from '../core/lib/manifest-parser.js';
@@ -16,7 +17,6 @@ import speedline from 'speedline-core';
16
17
  import * as CDTSourceMap from '../core/lib/cdt/generated/SourceMap.js';
17
18
  import {ArbitraryEqualityMap} from '../core/lib/arbitrary-equality-map.js';
18
19
  import type { TaskNode as _TaskNode } from '../core/lib/tracehouse/main-thread-tasks.js';
19
- import type {EnabledHandlers} from '../core/computed/trace-engine-result.js';
20
20
  import AuditDetails from './lhr/audit-details.js'
21
21
  import Config from './config.js';
22
22
  import Gatherer from './gatherer.js';
@@ -511,8 +511,8 @@ declare module Artifacts {
511
511
  }
512
512
 
513
513
  interface TraceEngineResult {
514
- data: TraceEngine.Handlers.Types.EnabledHandlerDataWithMeta<EnabledHandlers>;
515
- insights: TraceEngine.Insights.Types.TraceInsightData<EnabledHandlers>;
514
+ data: TraceEngine.Handlers.Types.TraceParseData;
515
+ insights: TraceEngine.Insights.Types.TraceInsightData<typeof TraceEngine.Handlers.ModelHandlers>;
516
516
  }
517
517
 
518
518
  interface TraceEngineRootCauses {
@@ -592,14 +592,7 @@ declare module Artifacts {
592
592
  throughput: number;
593
593
  }
594
594
 
595
- interface LanternMetric {
596
- timing: number;
597
- timestamp?: never;
598
- optimisticEstimate: Gatherer.Simulation.Result
599
- pessimisticEstimate: Gatherer.Simulation.Result;
600
- optimisticGraph: Gatherer.Simulation.GraphNode;
601
- pessimisticGraph: Gatherer.Simulation.GraphNode;
602
- }
595
+ type LanternMetric = Lantern.Metric<Artifacts.NetworkRequest>;
603
596
 
604
597
  type Speedline = speedline.Output<'speedIndex'>;
605
598