lighthouse 9.5.0-dev.20220329 → 9.5.0-dev.20220330

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 (59) hide show
  1. package/dist/report/bundle.esm.js +20 -18
  2. package/dist/report/flow.js +1 -1
  3. package/dist/report/standalone.js +1 -1
  4. package/lighthouse-cli/test/smokehouse/lighthouse-runners/devtools.js +26 -18
  5. package/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js +2 -1
  6. package/lighthouse-core/audits/byte-efficiency/efficient-animated-content.js +1 -1
  7. package/lighthouse-core/audits/byte-efficiency/offscreen-images.js +3 -2
  8. package/lighthouse-core/audits/byte-efficiency/render-blocking-resources.js +1 -1
  9. package/lighthouse-core/audits/byte-efficiency/unused-javascript.js +1 -1
  10. package/lighthouse-core/audits/byte-efficiency/uses-responsive-images.js +1 -1
  11. package/lighthouse-core/audits/byte-efficiency/uses-text-compression.js +1 -1
  12. package/lighthouse-core/audits/dobetterweb/uses-http2.js +2 -1
  13. package/lighthouse-core/audits/long-tasks.js +3 -2
  14. package/lighthouse-core/audits/metrics/first-contentful-paint-3g.js +2 -2
  15. package/lighthouse-core/audits/metrics/first-contentful-paint.js +3 -2
  16. package/lighthouse-core/audits/metrics/first-meaningful-paint.js +3 -2
  17. package/lighthouse-core/audits/metrics/interactive.js +3 -2
  18. package/lighthouse-core/audits/metrics/largest-contentful-paint.js +3 -2
  19. package/lighthouse-core/audits/metrics/max-potential-fid.js +3 -2
  20. package/lighthouse-core/audits/metrics/speed-index.js +3 -2
  21. package/lighthouse-core/audits/metrics/total-blocking-time.js +3 -2
  22. package/lighthouse-core/audits/metrics.js +3 -2
  23. package/lighthouse-core/audits/predictive-perf.js +2 -1
  24. package/lighthouse-core/audits/preload-lcp-image.js +1 -1
  25. package/lighthouse-core/audits/redirects.js +1 -1
  26. package/lighthouse-core/audits/timing-budget.js +3 -2
  27. package/lighthouse-core/audits/uses-rel-preconnect.js +1 -1
  28. package/lighthouse-core/audits/uses-rel-preload.js +1 -1
  29. package/lighthouse-core/computed/critical-request-chains.js +2 -9
  30. package/lighthouse-core/computed/main-resource.js +1 -1
  31. package/lighthouse-core/computed/metrics/first-contentful-paint-all-frames.js +1 -1
  32. package/lighthouse-core/computed/metrics/first-contentful-paint.js +1 -1
  33. package/lighthouse-core/computed/metrics/first-meaningful-paint.js +1 -1
  34. package/lighthouse-core/computed/metrics/interactive.js +1 -1
  35. package/lighthouse-core/computed/metrics/lantern-first-contentful-paint.js +1 -1
  36. package/lighthouse-core/computed/metrics/lantern-first-meaningful-paint.js +1 -1
  37. package/lighthouse-core/computed/metrics/lantern-interactive.js +1 -1
  38. package/lighthouse-core/computed/metrics/lantern-largest-contentful-paint.js +1 -1
  39. package/lighthouse-core/computed/metrics/lantern-max-potential-fid.js +1 -1
  40. package/lighthouse-core/computed/metrics/lantern-metric.js +3 -5
  41. package/lighthouse-core/computed/metrics/lantern-speed-index.js +1 -1
  42. package/lighthouse-core/computed/metrics/lantern-total-blocking-time.js +1 -1
  43. package/lighthouse-core/computed/metrics/largest-contentful-paint-all-frames.js +1 -1
  44. package/lighthouse-core/computed/metrics/largest-contentful-paint.js +1 -1
  45. package/lighthouse-core/computed/metrics/max-potential-fid.js +1 -1
  46. package/lighthouse-core/computed/metrics/metric.js +1 -0
  47. package/lighthouse-core/computed/metrics/speed-index.js +1 -1
  48. package/lighthouse-core/computed/metrics/timing-summary.js +13 -6
  49. package/lighthouse-core/computed/metrics/total-blocking-time.js +1 -1
  50. package/lighthouse-core/computed/page-dependency-graph.js +54 -31
  51. package/lighthouse-core/gather/driver/execution-context.js +4 -2
  52. package/lighthouse-core/gather/gatherers/js-usage.js +7 -6
  53. package/lighthouse-core/gather/gatherers/scripts.js +20 -2
  54. package/lighthouse-core/lib/dependency-graph/simulator/network-analyzer.js +8 -29
  55. package/lighthouse-core/lib/navigation-error.js +13 -4
  56. package/lighthouse-core/util-commonjs.js +20 -18
  57. package/package.json +1 -1
  58. package/report/renderer/util.js +20 -18
  59. package/types/artifacts.d.ts +1 -0
@@ -6,7 +6,6 @@
6
6
  'use strict';
7
7
 
8
8
  const INITIAL_CWD = 14 * 1024;
9
- const NetworkRequest = require('../../network-request.js');
10
9
  const URL = require('../../url-shim.js');
11
10
 
12
11
  // Assume that 40% of TTFB was server response time by default for static assets
@@ -434,40 +433,20 @@ class NetworkAnalyzer {
434
433
 
435
434
  /**
436
435
  * @param {Array<LH.Artifacts.NetworkRequest>} records
437
- * @param {string} [finalURL]
438
- * @return {LH.Artifacts.NetworkRequest}
439
- */
440
- static findMainDocument(records, finalURL) {
441
- const mainDocument = NetworkAnalyzer.findOptionalMainDocument(records, finalURL);
442
- if (!mainDocument) throw new Error('Unable to identify the main resource');
443
- return mainDocument;
444
- }
445
-
446
- /**
447
- * @param {Array<LH.Artifacts.NetworkRequest>} records
448
- * @param {string} [finalURL]
436
+ * @param {string} resourceUrl
449
437
  * @return {LH.Artifacts.NetworkRequest|undefined}
450
438
  */
451
- static findOptionalMainDocument(records, finalURL) {
452
- // Try to find an exact match with the final URL first if we have one
453
- if (finalURL) {
454
- // equalWithExcludedFragments is expensive, so check that the finalUrl starts with the request first
455
- const mainResource = records.find(request => finalURL.startsWith(request.url) &&
456
- URL.equalWithExcludedFragments(request.url, finalURL));
457
- if (mainResource) return mainResource;
458
- // TODO: beacon !mainResource to Sentry, https://github.com/GoogleChrome/lighthouse/issues/7041
459
- }
460
-
461
- const documentRequests = records.filter(record => record.resourceType ===
462
- NetworkRequest.TYPES.Document);
463
- if (!documentRequests.length) return undefined;
464
- // The main document is the earliest document request, using position in networkRecords array to break ties.
465
- return documentRequests.reduce((min, r) => (r.startTime < min.startTime ? r : min));
439
+ static findResourceForUrl(records, resourceUrl) {
440
+ // equalWithExcludedFragments is expensive, so check that the resourceUrl starts with the request url first
441
+ return records.find(request =>
442
+ resourceUrl.startsWith(request.url) &&
443
+ URL.equalWithExcludedFragments(request.url, resourceUrl)
444
+ );
466
445
  }
467
446
 
468
447
  /**
469
448
  * Resolves redirect chain given a main document.
470
- * See: {@link NetworkAnalyzer.findMainDocument}) for how to retrieve main document.
449
+ * See: {@link NetworkAnalyzer.findResourceForUrl}) for how to retrieve main document.
471
450
  *
472
451
  * @param {LH.Artifacts.NetworkRequest} request
473
452
  * @return {LH.Artifacts.NetworkRequest}
@@ -7,6 +7,7 @@
7
7
 
8
8
  const LHError = require('./lh-error.js');
9
9
  const NetworkAnalyzer = require('./dependency-graph/simulator/network-analyzer.js');
10
+ const NetworkRequest = require('./network-request.js');
10
11
 
11
12
  /**
12
13
  * Returns an error if the original network request failed or wasn't found.
@@ -100,10 +101,18 @@ function getNonHtmlError(finalRecord) {
100
101
  function getPageLoadError(navigationError, context) {
101
102
  const {url, loadFailureMode, networkRecords} = context;
102
103
  /** @type {LH.Artifacts.NetworkRequest|undefined} */
103
- let mainRecord;
104
- try {
105
- mainRecord = NetworkAnalyzer.findMainDocument(networkRecords, url);
106
- } catch (_) {}
104
+ let mainRecord = NetworkAnalyzer.findResourceForUrl(networkRecords, url);
105
+
106
+ // If the url doesn't give us a network request, it's possible we landed on a chrome-error:// page
107
+ // In this case, just get the first document request.
108
+ if (!mainRecord) {
109
+ const documentRequests = networkRecords.filter(record =>
110
+ record.resourceType === NetworkRequest.TYPES.Document
111
+ );
112
+ if (documentRequests.length) {
113
+ mainRecord = documentRequests.reduce((min, r) => (r.startTime < min.startTime ? r : min));
114
+ }
115
+ }
107
116
 
108
117
  // MIME Type is only set on the final redirected document request. Use this for the HTML check instead of root.
109
118
  let finalRecord;
@@ -318,24 +318,26 @@ class Util {
318
318
  }
319
319
 
320
320
  const MAX_LENGTH = 64;
321
- // Always elide hexadecimal hash
322
- name = name.replace(/([a-f0-9]{7})[a-f0-9]{13}[a-f0-9]*/g, `$1${ELLIPSIS}`);
323
- // Also elide other hash-like mixed-case strings
324
- name = name.replace(/([a-zA-Z0-9-_]{9})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9-_]{10,}/g,
325
- `$1${ELLIPSIS}`);
326
- // Also elide long number sequences
327
- name = name.replace(/(\d{3})\d{6,}/g, `$1${ELLIPSIS}`);
328
- // Merge any adjacent ellipses
329
- name = name.replace(/\u2026+/g, ELLIPSIS);
330
-
331
- // Elide query params first
332
- if (name.length > MAX_LENGTH && name.includes('?')) {
333
- // Try to leave the first query parameter intact
334
- name = name.replace(/\?([^=]*)(=)?.*/, `?$1$2${ELLIPSIS}`);
335
-
336
- // Remove it all if it's still too long
337
- if (name.length > MAX_LENGTH) {
338
- name = name.replace(/\?.*/, `?${ELLIPSIS}`);
321
+ if (parsedUrl.protocol !== 'data:') {
322
+ // Always elide hexadecimal hash
323
+ name = name.replace(/([a-f0-9]{7})[a-f0-9]{13}[a-f0-9]*/g, `$1${ELLIPSIS}`);
324
+ // Also elide other hash-like mixed-case strings
325
+ name = name.replace(/([a-zA-Z0-9-_]{9})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9-_]{10,}/g,
326
+ `$1${ELLIPSIS}`);
327
+ // Also elide long number sequences
328
+ name = name.replace(/(\d{3})\d{6,}/g, `$1${ELLIPSIS}`);
329
+ // Merge any adjacent ellipses
330
+ name = name.replace(/\u2026+/g, ELLIPSIS);
331
+
332
+ // Elide query params first
333
+ if (name.length > MAX_LENGTH && name.includes('?')) {
334
+ // Try to leave the first query parameter intact
335
+ name = name.replace(/\?([^=]*)(=)?.*/, `?$1$2${ELLIPSIS}`);
336
+
337
+ // Remove it all if it's still too long
338
+ if (name.length > MAX_LENGTH) {
339
+ name = name.replace(/\?.*/, `?${ELLIPSIS}`);
340
+ }
339
341
  }
340
342
  }
341
343
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lighthouse",
3
- "version": "9.5.0-dev.20220329",
3
+ "version": "9.5.0-dev.20220330",
4
4
  "description": "Automated auditing, performance metrics, and best practices for the web.",
5
5
  "main": "./lighthouse-core/index.js",
6
6
  "bin": {
@@ -315,24 +315,26 @@ class Util {
315
315
  }
316
316
 
317
317
  const MAX_LENGTH = 64;
318
- // Always elide hexadecimal hash
319
- name = name.replace(/([a-f0-9]{7})[a-f0-9]{13}[a-f0-9]*/g, `$1${ELLIPSIS}`);
320
- // Also elide other hash-like mixed-case strings
321
- name = name.replace(/([a-zA-Z0-9-_]{9})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9-_]{10,}/g,
322
- `$1${ELLIPSIS}`);
323
- // Also elide long number sequences
324
- name = name.replace(/(\d{3})\d{6,}/g, `$1${ELLIPSIS}`);
325
- // Merge any adjacent ellipses
326
- name = name.replace(/\u2026+/g, ELLIPSIS);
327
-
328
- // Elide query params first
329
- if (name.length > MAX_LENGTH && name.includes('?')) {
330
- // Try to leave the first query parameter intact
331
- name = name.replace(/\?([^=]*)(=)?.*/, `?$1$2${ELLIPSIS}`);
332
-
333
- // Remove it all if it's still too long
334
- if (name.length > MAX_LENGTH) {
335
- name = name.replace(/\?.*/, `?${ELLIPSIS}`);
318
+ if (parsedUrl.protocol !== 'data:') {
319
+ // Always elide hexadecimal hash
320
+ name = name.replace(/([a-f0-9]{7})[a-f0-9]{13}[a-f0-9]*/g, `$1${ELLIPSIS}`);
321
+ // Also elide other hash-like mixed-case strings
322
+ name = name.replace(/([a-zA-Z0-9-_]{9})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9-_]{10,}/g,
323
+ `$1${ELLIPSIS}`);
324
+ // Also elide long number sequences
325
+ name = name.replace(/(\d{3})\d{6,}/g, `$1${ELLIPSIS}`);
326
+ // Merge any adjacent ellipses
327
+ name = name.replace(/\u2026+/g, ELLIPSIS);
328
+
329
+ // Elide query params first
330
+ if (name.length > MAX_LENGTH && name.includes('?')) {
331
+ // Try to leave the first query parameter intact
332
+ name = name.replace(/\?([^=]*)(=)?.*/, `?$1$2${ELLIPSIS}`);
333
+
334
+ // Remove it all if it's still too long
335
+ if (name.length > MAX_LENGTH) {
336
+ name = name.replace(/\?.*/, `?${ELLIPSIS}`);
337
+ }
336
338
  }
337
339
  }
338
340
 
@@ -641,6 +641,7 @@ declare module Artifacts {
641
641
  settings: Immutable<Config.Settings>;
642
642
  gatherContext: Artifacts['GatherContext'];
643
643
  simulator?: InstanceType<typeof LanternSimulator>;
644
+ URL: Artifacts['URL'];
644
645
  }
645
646
 
646
647
  interface MetricComputationData extends MetricComputationDataInput {