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
@@ -2,7 +2,9 @@ export { TraceEngineResultComputed as TraceEngineResult };
2
2
  declare const TraceEngineResultComputed: typeof TraceEngineResult & {
3
3
  request: (dependencies: {
4
4
  trace: LH.Trace;
5
- settings: LH.Audit.Context["settings"];
5
+ settings: Partial<LH.Util.ImmutableObject<Pick<import("../../types/lhr/settings.js").ConfigSettings, "throttlingMethod"> & Partial<Omit<import("../../types/lhr/settings.js").ConfigSettings, "throttling">> & {
6
+ throttling?: Partial<LH.Config.Settings["throttling"]>;
7
+ }>>;
6
8
  SourceMaps: LH.Artifacts["SourceMaps"];
7
9
  HostDPR: LH.Artifacts["HostDPR"];
8
10
  }, context: LH.Artifacts.ComputedContext) => Promise<LH.Artifacts.TraceEngineResult>;
@@ -13,12 +15,12 @@ declare const TraceEngineResultComputed: typeof TraceEngineResult & {
13
15
  declare class TraceEngineResult {
14
16
  /**
15
17
  * @param {LH.TraceEvent[]} _traceEvents
16
- * @param {LH.Audit.Context['settings']} settings
18
+ * @param {Partial<LH.Artifacts.ComputedSettings>} settings
17
19
  * @param {LH.Artifacts['SourceMaps']} SourceMaps
18
20
  * @param {LH.Artifacts['HostDPR']} HostDPR
19
21
  * @return {Promise<LH.Artifacts.TraceEngineResult>}
20
22
  */
21
- static runTraceEngine(_traceEvents: LH.TraceEvent[], settings: LH.Audit.Context["settings"], SourceMaps: LH.Artifacts["SourceMaps"], HostDPR: LH.Artifacts["HostDPR"]): Promise<LH.Artifacts.TraceEngineResult>;
23
+ static runTraceEngine(_traceEvents: LH.TraceEvent[], settings: Partial<LH.Artifacts.ComputedSettings>, SourceMaps: LH.Artifacts["SourceMaps"], HostDPR: LH.Artifacts["HostDPR"]): Promise<LH.Artifacts.TraceEngineResult>;
22
24
  /**
23
25
  * Adapts the given DevTools function that returns a localized string to one
24
26
  * that returns a LH.IcuMessage.
@@ -51,13 +53,13 @@ declare class TraceEngineResult {
51
53
  */
52
54
  static localizeInsights(insightSets: import("@paulirish/trace_engine/models/trace/insights/types.js").TraceInsightSets): void;
53
55
  /**
54
- * @param {{trace: LH.Trace, settings: LH.Audit.Context['settings'], SourceMaps: LH.Artifacts['SourceMaps'], HostDPR: LH.Artifacts['HostDPR']}} data
56
+ * @param {{trace: LH.Trace, settings: Partial<LH.Artifacts.ComputedSettings>, SourceMaps: LH.Artifacts['SourceMaps'], HostDPR: LH.Artifacts['HostDPR']}} data
55
57
  * @param {LH.Artifacts.ComputedContext} context
56
58
  * @return {Promise<LH.Artifacts.TraceEngineResult>}
57
59
  */
58
60
  static compute_(data: {
59
61
  trace: LH.Trace;
60
- settings: LH.Audit.Context["settings"];
62
+ settings: Partial<LH.Artifacts.ComputedSettings>;
61
63
  SourceMaps: LH.Artifacts["SourceMaps"];
62
64
  HostDPR: LH.Artifacts["HostDPR"];
63
65
  }, context: LH.Artifacts.ComputedContext): Promise<LH.Artifacts.TraceEngineResult>;
@@ -4,8 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import log from 'lighthouse-logger';
8
-
7
+ import log from '../lib/lighthouse-logger.js';
9
8
  import * as i18n from '../lib/i18n/i18n.js';
10
9
  import * as Lantern from '../lib/lantern/lantern.js';
11
10
  import * as TraceEngine from '../lib/trace-engine.js';
@@ -21,7 +20,7 @@ import * as LH from '../../types/lh.js';
21
20
  class TraceEngineResult {
22
21
  /**
23
22
  * @param {LH.TraceEvent[]} _traceEvents
24
- * @param {LH.Audit.Context['settings']} settings
23
+ * @param {Partial<LH.Artifacts.ComputedSettings>} settings
25
24
  * @param {LH.Artifacts['SourceMaps']} SourceMaps
26
25
  * @param {LH.Artifacts['HostDPR']} HostDPR
27
26
  * @return {Promise<LH.Artifacts.TraceEngineResult>}
@@ -35,7 +34,12 @@ class TraceEngineResult {
35
34
 
36
35
  const lanternSettings = {};
37
36
  if (settings.throttlingMethod) lanternSettings.throttlingMethod = settings.throttlingMethod;
38
- if (settings.throttling) lanternSettings.throttling = settings.throttling;
37
+ if (settings.throttling) {
38
+ lanternSettings.throttling = {
39
+ ...Lantern.Simulation.Constants.throttling.mobileSlow4G,
40
+ ...settings.throttling,
41
+ };
42
+ }
39
43
  if (settings.precomputedLanternData) {
40
44
  lanternSettings.precomputedLanternData = settings.precomputedLanternData;
41
45
  }
@@ -237,7 +241,7 @@ class TraceEngineResult {
237
241
  }
238
242
 
239
243
  /**
240
- * @param {{trace: LH.Trace, settings: LH.Audit.Context['settings'], SourceMaps: LH.Artifacts['SourceMaps'], HostDPR: LH.Artifacts['HostDPR']}} data
244
+ * @param {{trace: LH.Trace, settings: Partial<LH.Artifacts.ComputedSettings>, SourceMaps: LH.Artifacts['SourceMaps'], HostDPR: LH.Artifacts['HostDPR']}} data
241
245
  * @param {LH.Artifacts.ComputedContext} context
242
246
  * @return {Promise<LH.Artifacts.TraceEngineResult>}
243
247
  */
@@ -1,6 +1,6 @@
1
1
  export { UnusedCSSComputed as UnusedCSS };
2
2
  export type StyleSheetInfo = LH.Artifacts.CSSStyleSheetInfo & {
3
- networkRecord: LH.Artifacts.NetworkRequest;
3
+ networkRecord: LH.Artifacts.NetworkRequest | undefined;
4
4
  usedRules: Array<LH.Crdp.CSS.RuleUsage>;
5
5
  };
6
6
  declare const UnusedCSSComputed: typeof UnusedCSS & {
@@ -10,7 +10,7 @@ declare const UnusedCSSComputed: typeof UnusedCSS & {
10
10
  devtoolsLog: LH.DevtoolsLog;
11
11
  }, context: LH.Artifacts.ComputedContext) => Promise<import("../../types.js").Audit.ByteEfficiencyItem[]>;
12
12
  };
13
- /** @typedef {LH.Artifacts.CSSStyleSheetInfo & {networkRecord: LH.Artifacts.NetworkRequest, usedRules: Array<LH.Crdp.CSS.RuleUsage>}} StyleSheetInfo */
13
+ /** @typedef {LH.Artifacts.CSSStyleSheetInfo & {networkRecord: LH.Artifacts.NetworkRequest|undefined, usedRules: Array<LH.Crdp.CSS.RuleUsage>}} StyleSheetInfo */
14
14
  declare class UnusedCSS {
15
15
  /**
16
16
  * @param {Array<LH.Artifacts.CSSStyleSheetInfo>} styles The output of the Styles gatherer.
@@ -11,7 +11,7 @@ import {estimateCompressedContentSize} from '../lib/script-helpers.js';
11
11
 
12
12
  const PREVIEW_LENGTH = 100;
13
13
 
14
- /** @typedef {LH.Artifacts.CSSStyleSheetInfo & {networkRecord: LH.Artifacts.NetworkRequest, usedRules: Array<LH.Crdp.CSS.RuleUsage>}} StyleSheetInfo */
14
+ /** @typedef {LH.Artifacts.CSSStyleSheetInfo & {networkRecord: LH.Artifacts.NetworkRequest|undefined, usedRules: Array<LH.Crdp.CSS.RuleUsage>}} StyleSheetInfo */
15
15
 
16
16
  class UnusedCSS {
17
17
  /**
@@ -6,8 +6,7 @@
6
6
 
7
7
  import path from 'path';
8
8
 
9
- import log from 'lighthouse-logger';
10
-
9
+ import log from '../lib/lighthouse-logger.js';
11
10
  import * as LH from '../../types/lh.js';
12
11
  import {Runner} from '../runner.js';
13
12
  import defaultConfig from './default-config.js';
@@ -4,8 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import log from 'lighthouse-logger';
8
-
7
+ import log from '../lib/lighthouse-logger.js';
9
8
  import {
10
9
  getBrowserVersion, getBenchmarkIndex, getEnvironmentWarnings,
11
10
  getDevicePixelRatio,
@@ -4,8 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import log from 'lighthouse-logger';
8
-
7
+ import log from '../../lib/lighthouse-logger.js';
9
8
  import * as constants from '../../config/constants.js';
10
9
  import {pageFunctions} from '../../lib/page-functions.js';
11
10
  import * as i18n from '../../lib/i18n/i18n.js';
@@ -324,6 +324,7 @@ class ExecutionContext {
324
324
  window.__nativeURL = window.URL;
325
325
  window.__nativePerformance = window.performance;
326
326
  window.__nativeFetch = window.fetch;
327
+ window.__nativeMap = window.Map;
327
328
  window.__ElementMatches = window.Element.prototype.matches;
328
329
  window.__HTMLElementBoundingClientRect = window.HTMLElement.prototype.getBoundingClientRect;
329
330
  }, {args: []});
@@ -339,6 +340,7 @@ class ExecutionContext {
339
340
  'const URL = globalThis.__nativeURL || globalThis.URL',
340
341
  'const performance = globalThis.__nativePerformance || globalThis.performance',
341
342
  'const fetch = globalThis.__nativeFetch || globalThis.fetch',
343
+ 'const Map = globalThis.__nativeMap || globalThis.Map',
342
344
  ].join(';\n');
343
345
 
344
346
  /**
@@ -4,8 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import log from 'lighthouse-logger';
8
-
7
+ import log from '../../lib/lighthouse-logger.js';
9
8
  import {waitForFullyLoaded, waitForFrameNavigated, waitForUserToContinue} from './wait-for-condition.js';
10
9
  import * as constants from '../../config/constants.js';
11
10
  import * as i18n from '../../lib/i18n/i18n.js';
@@ -11,8 +11,7 @@
11
11
 
12
12
  import {EventEmitter} from 'events';
13
13
 
14
- import log from 'lighthouse-logger';
15
-
14
+ import log from '../../lib/lighthouse-logger.js';
16
15
  import * as LH from '../../../types/lh.js';
17
16
  import {NetworkRecorder} from '../../lib/network-recorder.js';
18
17
  import {NetworkRequest} from '../../lib/network-request.js';
@@ -4,8 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import log from 'lighthouse-logger';
8
-
7
+ import log from '../../lib/lighthouse-logger.js';
9
8
  import * as storage from './storage.js';
10
9
  import * as emulation from '../../lib/emulation.js';
11
10
  import {pageFunctions} from '../../lib/page-functions.js';
@@ -4,8 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import log from 'lighthouse-logger';
8
-
7
+ import log from '../../lib/lighthouse-logger.js';
9
8
  import * as i18n from '../../lib/i18n/i18n.js';
10
9
  import {Sentry} from '../../lib/sentry.js';
11
10
 
@@ -11,8 +11,7 @@
11
11
 
12
12
  import EventEmitter from 'events';
13
13
 
14
- import log from 'lighthouse-logger';
15
-
14
+ import log from '../../lib/lighthouse-logger.js';
16
15
  import {ProtocolSession} from '../session.js';
17
16
 
18
17
  /**
@@ -6,8 +6,7 @@
6
6
 
7
7
  /* global window */
8
8
 
9
- import log from 'lighthouse-logger';
10
-
9
+ import log from '../../lib/lighthouse-logger.js';
11
10
  import {LighthouseError} from '../../lib/lh-error.js';
12
11
  import {ExecutionContext} from './execution-context.js';
13
12
 
@@ -231,9 +230,10 @@ function waitForCPUIdle(session, waitForCPUQuiet) {
231
230
  /**
232
231
  * @param {ExecutionContext} executionContext
233
232
  * @param {() => void} resolve
233
+ * @param {(err: Error) => void} reject
234
234
  * @return {Promise<void>}
235
235
  */
236
- async function checkForQuiet(executionContext, resolve) {
236
+ async function checkForQuiet(executionContext, resolve, reject) {
237
237
  if (canceled) return;
238
238
  const timeSinceLongTask =
239
239
  await executionContext.evaluate(
@@ -247,7 +247,8 @@ function waitForCPUIdle(session, waitForCPUQuiet) {
247
247
  } else {
248
248
  log.verbose('waitFor', `CPU has been idle for ${timeSinceLongTask} ms`);
249
249
  const timeToWait = waitForCPUQuiet - timeSinceLongTask;
250
- lastTimeout = setTimeout(() => checkForQuiet(executionContext, resolve), timeToWait);
250
+ lastTimeout = setTimeout(
251
+ () => checkForQuiet(executionContext, resolve, reject).catch(reject), timeToWait);
251
252
  }
252
253
  }
253
254
  }
@@ -261,7 +262,7 @@ function waitForCPUIdle(session, waitForCPUQuiet) {
261
262
  /** @type {Promise<void>} */
262
263
  const promise = new Promise((resolve, reject) => {
263
264
  executionContext.evaluate(registerPerformanceObserverInPage, {args: [], useIsolation: true})
264
- .then(() => checkForQuiet(executionContext, resolve))
265
+ .then(() => checkForQuiet(executionContext, resolve, reject))
265
266
  .catch(reject);
266
267
  cancel = () => {
267
268
  if (canceled) return;
@@ -4,8 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import log from 'lighthouse-logger';
8
-
7
+ import log from '../lib/lighthouse-logger.js';
9
8
  import {ExecutionContext} from './driver/execution-context.js';
10
9
  import {TargetManager} from './driver/target-manager.js';
11
10
  import {Fetcher} from './fetcher.js';
@@ -11,9 +11,9 @@
11
11
  * @see https://agenticresourcediscovery.org/spec/
12
12
  */
13
13
 
14
- import log from 'lighthouse-logger';
15
14
  import LinkHeader from 'http-link-header';
16
15
 
16
+ import log from '../../../lib/lighthouse-logger.js';
17
17
  import BaseGatherer from '../../base-gatherer.js';
18
18
  import RobotsTxt from '../seo/robots-txt.js';
19
19
  import * as Lantern from '../../../lib/lantern/lantern.js';
@@ -4,8 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import log from 'lighthouse-logger';
8
-
7
+ import log from '../../../lib/lighthouse-logger.js';
9
8
  import BaseGatherer from '../../base-gatherer.js';
10
9
 
11
10
  class LlmsTxt extends BaseGatherer {
@@ -30,7 +30,11 @@ class CSSUsage extends BaseGatherer {
30
30
 
31
31
  // Force style to recompute.
32
32
  // Doesn't appear to be necessary in newer versions of Chrome.
33
- await executionContext.evaluate(() => window.getComputedStyle(document.body), {
33
+ // `document.body` is null for some documents (e.g. XML or SVG).
34
+ await executionContext.evaluate(() => {
35
+ const el = document.body || document.documentElement;
36
+ if (el) window.getComputedStyle(el);
37
+ }, {
34
38
  args: [],
35
39
  });
36
40
 
@@ -9,8 +9,7 @@
9
9
  * and attribute information. Executes script in the context of the page.
10
10
  */
11
11
 
12
- import log from 'lighthouse-logger';
13
-
12
+ import log from '../../lib/lighthouse-logger.js';
14
13
  import BaseGatherer from '../base-gatherer.js';
15
14
  import {pageFunctions} from '../../lib/page-functions.js';
16
15
 
@@ -4,8 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import log from 'lighthouse-logger';
8
-
7
+ import log from '../../../lib/lighthouse-logger.js';
9
8
  import BaseGatherer from '../../base-gatherer.js';
10
9
 
11
10
  class RobotsTxt extends BaseGatherer {
@@ -13,8 +13,7 @@
13
13
  import fs from 'fs';
14
14
  import {createRequire} from 'module';
15
15
 
16
- import log from 'lighthouse-logger';
17
-
16
+ import log from '../../lib/lighthouse-logger.js';
18
17
  import BaseGatherer from '../base-gatherer.js';
19
18
 
20
19
 
@@ -8,8 +8,7 @@
8
8
  * @fileoverview Collects all stylesheets and their contents.
9
9
  */
10
10
 
11
- import log from 'lighthouse-logger';
12
-
11
+ import log from '../../lib/lighthouse-logger.js';
13
12
  import BaseGatherer from '../base-gatherer.js';
14
13
  import {Sentry} from '../../lib/sentry.js';
15
14
 
@@ -44,6 +43,10 @@ class Stylesheets extends BaseGatherer {
44
43
  'Stylesheets',
45
44
  `Error fetching content of stylesheet with URL "${event.header.sourceURL}"`
46
45
  );
46
+ // The stylesheet can be removed between `styleSheetAdded` and fetching its text.
47
+ // This is an expected race, so don't report it.
48
+ if (/No style sheet with given id/.test(err.protocolError)) return null;
49
+
47
50
  Sentry.captureException(err, {
48
51
  tags: {
49
52
  gatherer: 'Stylesheets',
@@ -74,7 +77,11 @@ class Stylesheets extends BaseGatherer {
74
77
 
75
78
  // Force style to recompute.
76
79
  // Doesn't appear to be necessary in newer versions of Chrome.
77
- await executionContext.evaluate(() => window.getComputedStyle(document.body), {
80
+ // `document.body` is null for some documents (e.g. XML or SVG).
81
+ await executionContext.evaluate(() => {
82
+ const el = document.body || document.documentElement;
83
+ if (el) window.getComputedStyle(el);
84
+ }, {
78
85
  args: [],
79
86
  });
80
87
 
@@ -5,8 +5,8 @@
5
5
  */
6
6
 
7
7
  import puppeteer from 'puppeteer-core';
8
- import log from 'lighthouse-logger';
9
8
 
9
+ import log from '../lib/lighthouse-logger.js';
10
10
  import {Driver} from './driver.js';
11
11
  import {Runner} from '../runner.js';
12
12
  import {getEmptyArtifactState, collectPhaseArtifacts, awaitArtifacts} from './runner-helpers.js';
@@ -23,8 +23,7 @@
23
23
 
24
24
  /** @typedef {LH.Gatherer.Context<LH.Gatherer.DependencyKey>['dependencies']} Dependencies */
25
25
 
26
- import log from 'lighthouse-logger';
27
-
26
+ import log from '../lib/lighthouse-logger.js';
28
27
  import {Sentry} from '../lib/sentry.js';
29
28
 
30
29
  /**
@@ -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 '../lib/lighthouse-logger.js';
11
10
  import {LighthouseError} from '../lib/lh-error.js';
12
11
 
13
12
  // Controls how long to wait for a response after sending a DevTools protocol command.
@@ -4,8 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import log from 'lighthouse-logger';
8
-
7
+ import log from '../lib/lighthouse-logger.js';
9
8
  import {Driver} from './driver.js';
10
9
  import {Runner} from '../runner.js';
11
10
  import {getEmptyArtifactState, collectPhaseArtifacts, awaitArtifacts} from './runner-helpers.js';
@@ -4,8 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import log from 'lighthouse-logger';
8
-
7
+ import log from '../lib/lighthouse-logger.js';
9
8
  import {Driver} from './driver.js';
10
9
  import {Runner} from '../runner.js';
11
10
  import {getEmptyArtifactState, collectPhaseArtifacts, awaitArtifacts} from './runner-helpers.js';
@@ -10,8 +10,7 @@ import stream from 'stream';
10
10
  import url from 'url';
11
11
  import {createGzip, gunzipSync} from 'zlib';
12
12
 
13
- import log from 'lighthouse-logger';
14
-
13
+ import log from './lighthouse-logger.js';
15
14
  import * as Lantern from './lantern/lantern.js';
16
15
  import lanternTraceSaver from './lantern-trace-saver.js';
17
16
  import {MetricTraceEvents} from './traces/metric-trace-events.js';
@@ -12,8 +12,8 @@ import {
12
12
  import {Type} from 'csp_evaluator/dist/finding.js';
13
13
  import {CspParser} from 'csp_evaluator/dist/parser.js';
14
14
  import {Directive} from 'csp_evaluator/dist/csp.js';
15
- import log from 'lighthouse-logger';
16
15
 
16
+ import log from './lighthouse-logger.js';
17
17
  import * as i18n from '../lib/i18n/i18n.js';
18
18
  import {isIcuMessage} from '../../shared/localization/format.js';
19
19
 
@@ -7,8 +7,7 @@
7
7
  import path from 'path';
8
8
  import url from 'url';
9
9
 
10
- import log from 'lighthouse-logger';
11
-
10
+ import log from '../lighthouse-logger.js';
12
11
  import {
13
12
  getAvailableLocales,
14
13
  isIcuMessage,
@@ -31,11 +31,9 @@ function convertNodeTimingsToTrace(nodeTimings) {
31
31
  // Represent all CPU work that was bundled in a task as an EvaluateScript event
32
32
  traceEvents.push(...createFakeTaskEvents(node, timing));
33
33
  } else {
34
- /** @type {LH.Artifacts.NetworkRequest} */
35
- const record = node.rawRequest;
36
34
  // Ignore data URIs as they don't really add much value
37
- if (/^data/.test(record.url)) continue;
38
- traceEvents.push(...createFakeNetworkEvents(requestId, record, timing));
35
+ if (/^data/.test(node.request.url)) continue;
36
+ traceEvents.push(...createFakeNetworkEvents(requestId, node, timing));
39
37
  requestId++;
40
38
  }
41
39
  }
@@ -123,11 +121,10 @@ function convertNodeTimingsToTrace(nodeTimings) {
123
121
 
124
122
  /**
125
123
  * @param {number} requestId
126
- * @param {LH.Artifacts.NetworkRequest} record
127
124
  * @param {CompleteNodeTiming} timing
128
125
  * @return {LH.TraceEvent}
129
126
  */
130
- function createWillSendRequestEvent(requestId, record, timing) {
127
+ function createWillSendRequestEvent(requestId, timing) {
131
128
  return {
132
129
  ...baseEvent,
133
130
  ph: 'I',
@@ -142,11 +139,11 @@ function convertNodeTimingsToTrace(nodeTimings) {
142
139
 
143
140
  /**
144
141
  * @param {number} requestId
145
- * @param {LH.Artifacts.NetworkRequest} record
142
+ * @param {LH.Gatherer.Simulation.GraphNetworkNode} node
146
143
  * @param {CompleteNodeTiming} timing
147
144
  * @return {LH.TraceEvent[]}
148
145
  */
149
- function createFakeNetworkEvents(requestId, record, timing) {
146
+ function createFakeNetworkEvents(requestId, node, timing) {
150
147
  if (!('connectionTiming' in timing)) {
151
148
  throw new Error('Network node timing incomplete');
152
149
  }
@@ -156,6 +153,12 @@ function convertNodeTimingsToTrace(nodeTimings) {
156
153
  let {startTime, endTime} = timing;
157
154
  if (startTime === endTime) endTime += 0.3;
158
155
 
156
+ // Use the Lantern request rather than `rawRequest`, which is only an LH.Artifacts.NetworkRequest
157
+ // for graphs built by Lighthouse (not for those built by the trace engine).
158
+ const record = node.request;
159
+ /** @type {Partial<LH.Artifacts.NetworkRequest>|undefined} */
160
+ const rawRequest = node.rawRequest;
161
+
159
162
  const requestData = {requestId: requestId.toString(), frame};
160
163
  // No `dur` on network instant events but add to keep types happy.
161
164
  /** @type {LH.Util.StrictOmit<LH.TraceEvent, 'name'|'ts'|'args'>} */
@@ -163,12 +166,15 @@ function convertNodeTimingsToTrace(nodeTimings) {
163
166
 
164
167
  const sendRequestData = {
165
168
  ...requestData,
166
- requestMethod: record.requestMethod,
169
+ requestMethod: rawRequest?.requestMethod,
167
170
  url: record.url,
168
171
  priority: record.priority,
169
172
  };
170
173
 
171
- const {dnsResolutionTime, connectionTime, sslTime, timeToFirstByte} = timing.connectionTiming;
174
+ // Connectionless requests (disk cache, blob:, filesystem:, etc.) are simulated without
175
+ // any connection timing.
176
+ const {dnsResolutionTime, connectionTime, sslTime, timeToFirstByte} =
177
+ timing.connectionTiming || {};
172
178
  let sslStart = -1;
173
179
  let sslEnd = -1;
174
180
  if (connectionTime !== undefined && sslTime !== undefined) {
@@ -181,7 +187,7 @@ function convertNodeTimingsToTrace(nodeTimings) {
181
187
  mimeType: record.mimeType,
182
188
  encodedDataLength: record.transferSize,
183
189
  fromCache: record.fromDiskCache,
184
- fromServiceWorker: record.fetchedViaServiceWorker,
190
+ fromServiceWorker: rawRequest?.fetchedViaServiceWorker,
185
191
  timing: {
186
192
  // `requestTime` is in seconds.
187
193
  requestTime: toMicroseconds(startTime) / (1000 * 1000),
@@ -194,7 +200,7 @@ function convertNodeTimingsToTrace(nodeTimings) {
194
200
  sslEnd,
195
201
  sendStart: connectionTime ?? 0,
196
202
  sendEnd: connectionTime ?? 0,
197
- receiveHeadersEnd: timeToFirstByte,
203
+ receiveHeadersEnd: timeToFirstByte ?? 0,
198
204
  workerStart: -1,
199
205
  workerReady: -1,
200
206
  proxyStart: -1,
@@ -217,7 +223,7 @@ function convertNodeTimingsToTrace(nodeTimings) {
217
223
 
218
224
  // Navigation request needs an additional ResourceWillSendRequest event.
219
225
  if (requestId === 1) {
220
- events.push(createWillSendRequestEvent(requestId, record, timing));
226
+ events.push(createWillSendRequestEvent(requestId, timing));
221
227
  }
222
228
 
223
229
  events.push(