lighthouse 9.5.0-dev.20220509 → 9.6.1

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 (259) hide show
  1. package/changelog.md +70 -0
  2. package/dist/report/bundle.esm.js +400 -808
  3. package/dist/report/flow.js +22 -27
  4. package/dist/report/standalone.js +18 -23
  5. package/flow-report/src/summary/category.tsx +1 -1
  6. package/jest.config.js +1 -1
  7. package/lighthouse-cli/.eslintrc.cjs +4 -3
  8. package/lighthouse-cli/bin.js +1 -0
  9. package/lighthouse-cli/cli-flags.js +4 -3
  10. package/lighthouse-cli/commands/commands.js +1 -0
  11. package/lighthouse-cli/commands/list-audits.js +1 -0
  12. package/lighthouse-cli/commands/list-locales.js +1 -0
  13. package/lighthouse-cli/commands/list-trace-categories.js +1 -0
  14. package/lighthouse-cli/index.js +1 -0
  15. package/lighthouse-cli/printer.js +1 -0
  16. package/lighthouse-cli/run.js +24 -9
  17. package/lighthouse-cli/sentry-prompt.js +1 -0
  18. package/lighthouse-cli/test/smokehouse/core-tests.js +1 -0
  19. package/lighthouse-cli/test/smokehouse/frontends/back-compat-util.js +1 -0
  20. package/lighthouse-cli/test/smokehouse/frontends/lib.js +1 -0
  21. package/lighthouse-cli/test/smokehouse/frontends/node.js +1 -0
  22. package/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js +1 -0
  23. package/lighthouse-cli/test/smokehouse/lib/child-process-error.js +1 -0
  24. package/lighthouse-cli/test/smokehouse/lib/concurrent-mapper.js +1 -0
  25. package/lighthouse-cli/test/smokehouse/lib/local-console.js +1 -0
  26. package/lighthouse-cli/test/smokehouse/lighthouse-runners/bundle.js +23 -109
  27. package/lighthouse-cli/test/smokehouse/lighthouse-runners/cli.js +3 -2
  28. package/lighthouse-cli/test/smokehouse/lighthouse-runners/devtools.js +19 -28
  29. package/lighthouse-cli/test/smokehouse/report-assert.js +4 -3
  30. package/lighthouse-cli/test/smokehouse/smokehouse.js +1 -1
  31. package/lighthouse-cli/test/smokehouse/version-check-test.js +3 -0
  32. package/lighthouse-cli/test/smokehouse/version-check.js +1 -0
  33. package/lighthouse-core/audits/accessibility/accesskeys.js +1 -1
  34. package/lighthouse-core/audits/accessibility/aria-allowed-attr.js +1 -1
  35. package/lighthouse-core/audits/accessibility/aria-command-name.js +1 -1
  36. package/lighthouse-core/audits/accessibility/aria-hidden-body.js +1 -1
  37. package/lighthouse-core/audits/accessibility/aria-hidden-focus.js +1 -1
  38. package/lighthouse-core/audits/accessibility/aria-input-field-name.js +1 -1
  39. package/lighthouse-core/audits/accessibility/aria-meter-name.js +1 -1
  40. package/lighthouse-core/audits/accessibility/aria-progressbar-name.js +1 -1
  41. package/lighthouse-core/audits/accessibility/aria-required-attr.js +1 -1
  42. package/lighthouse-core/audits/accessibility/aria-required-children.js +1 -1
  43. package/lighthouse-core/audits/accessibility/aria-required-parent.js +1 -1
  44. package/lighthouse-core/audits/accessibility/aria-roles.js +1 -1
  45. package/lighthouse-core/audits/accessibility/aria-toggle-field-name.js +1 -1
  46. package/lighthouse-core/audits/accessibility/aria-tooltip-name.js +1 -1
  47. package/lighthouse-core/audits/accessibility/aria-treeitem-name.js +1 -1
  48. package/lighthouse-core/audits/accessibility/aria-valid-attr-value.js +1 -1
  49. package/lighthouse-core/audits/accessibility/aria-valid-attr.js +1 -1
  50. package/lighthouse-core/audits/accessibility/button-name.js +1 -1
  51. package/lighthouse-core/audits/accessibility/bypass.js +1 -1
  52. package/lighthouse-core/audits/accessibility/color-contrast.js +1 -1
  53. package/lighthouse-core/audits/accessibility/definition-list.js +1 -1
  54. package/lighthouse-core/audits/accessibility/dlitem.js +1 -1
  55. package/lighthouse-core/audits/accessibility/document-title.js +1 -1
  56. package/lighthouse-core/audits/accessibility/duplicate-id-active.js +1 -1
  57. package/lighthouse-core/audits/accessibility/duplicate-id-aria.js +1 -1
  58. package/lighthouse-core/audits/accessibility/form-field-multiple-labels.js +1 -1
  59. package/lighthouse-core/audits/accessibility/frame-title.js +1 -1
  60. package/lighthouse-core/audits/accessibility/heading-order.js +1 -1
  61. package/lighthouse-core/audits/accessibility/html-has-lang.js +1 -1
  62. package/lighthouse-core/audits/accessibility/html-lang-valid.js +1 -1
  63. package/lighthouse-core/audits/accessibility/image-alt.js +1 -1
  64. package/lighthouse-core/audits/accessibility/input-image-alt.js +1 -1
  65. package/lighthouse-core/audits/accessibility/label.js +1 -1
  66. package/lighthouse-core/audits/accessibility/link-name.js +1 -1
  67. package/lighthouse-core/audits/accessibility/list.js +1 -1
  68. package/lighthouse-core/audits/accessibility/listitem.js +5 -5
  69. package/lighthouse-core/audits/accessibility/meta-refresh.js +1 -1
  70. package/lighthouse-core/audits/accessibility/meta-viewport.js +1 -1
  71. package/lighthouse-core/audits/accessibility/object-alt.js +1 -1
  72. package/lighthouse-core/audits/accessibility/tabindex.js +1 -1
  73. package/lighthouse-core/audits/accessibility/td-headers-attr.js +1 -1
  74. package/lighthouse-core/audits/accessibility/th-has-data-cells.js +1 -1
  75. package/lighthouse-core/audits/accessibility/valid-lang.js +1 -1
  76. package/lighthouse-core/audits/accessibility/video-caption.js +1 -1
  77. package/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js +1 -2
  78. package/lighthouse-core/audits/byte-efficiency/duplicated-javascript.js +12 -11
  79. package/lighthouse-core/audits/byte-efficiency/efficient-animated-content.js +1 -1
  80. package/lighthouse-core/audits/byte-efficiency/legacy-javascript.js +24 -22
  81. package/lighthouse-core/audits/byte-efficiency/offscreen-images.js +2 -3
  82. package/lighthouse-core/audits/byte-efficiency/render-blocking-resources.js +3 -2
  83. package/lighthouse-core/audits/byte-efficiency/unminified-css.js +5 -3
  84. package/lighthouse-core/audits/byte-efficiency/unminified-javascript.js +11 -10
  85. package/lighthouse-core/audits/byte-efficiency/unused-css-rules.js +1 -0
  86. package/lighthouse-core/audits/byte-efficiency/unused-javascript.js +8 -11
  87. package/lighthouse-core/audits/byte-efficiency/uses-responsive-images.js +1 -1
  88. package/lighthouse-core/audits/byte-efficiency/uses-text-compression.js +1 -1
  89. package/lighthouse-core/audits/deprecations.js +598 -8
  90. package/lighthouse-core/audits/diagnostics.js +3 -4
  91. package/lighthouse-core/audits/dobetterweb/doctype.js +9 -20
  92. package/lighthouse-core/audits/dobetterweb/geolocation-on-start.js +1 -1
  93. package/lighthouse-core/audits/dobetterweb/no-document-write.js +1 -1
  94. package/lighthouse-core/audits/dobetterweb/notification-on-start.js +1 -1
  95. package/lighthouse-core/audits/dobetterweb/uses-http2.js +1 -2
  96. package/lighthouse-core/audits/dobetterweb/uses-passive-event-listeners.js +1 -1
  97. package/lighthouse-core/audits/errors-in-console.js +2 -2
  98. package/lighthouse-core/audits/long-tasks.js +2 -3
  99. package/lighthouse-core/audits/metrics/experimental-interaction-to-next-paint.js +3 -1
  100. package/lighthouse-core/audits/metrics/first-contentful-paint-3g.js +2 -2
  101. package/lighthouse-core/audits/metrics/first-contentful-paint.js +2 -3
  102. package/lighthouse-core/audits/metrics/first-meaningful-paint.js +2 -3
  103. package/lighthouse-core/audits/metrics/interactive.js +2 -3
  104. package/lighthouse-core/audits/metrics/largest-contentful-paint.js +2 -3
  105. package/lighthouse-core/audits/metrics/max-potential-fid.js +2 -3
  106. package/lighthouse-core/audits/metrics/speed-index.js +2 -3
  107. package/lighthouse-core/audits/metrics/total-blocking-time.js +2 -3
  108. package/lighthouse-core/audits/metrics.js +2 -3
  109. package/lighthouse-core/audits/no-unload-listeners.js +15 -7
  110. package/lighthouse-core/audits/predictive-perf.js +1 -2
  111. package/lighthouse-core/audits/preload-lcp-image.js +3 -3
  112. package/lighthouse-core/audits/redirects.js +1 -1
  113. package/lighthouse-core/audits/script-treemap-data.js +45 -45
  114. package/lighthouse-core/audits/seo/http-status-code.js +4 -2
  115. package/lighthouse-core/audits/seo/link-text.js +0 -2
  116. package/lighthouse-core/audits/server-response-time.js +17 -2
  117. package/lighthouse-core/audits/service-worker.js +2 -7
  118. package/lighthouse-core/audits/timing-budget.js +2 -3
  119. package/lighthouse-core/audits/uses-rel-preconnect.js +1 -1
  120. package/lighthouse-core/audits/uses-rel-preload.js +1 -1
  121. package/lighthouse-core/audits/valid-source-maps.js +14 -12
  122. package/lighthouse-core/audits/violation-audit.js +1 -1
  123. package/lighthouse-core/audits/work-during-interaction.js +280 -0
  124. package/lighthouse-core/computed/critical-request-chains.js +9 -5
  125. package/lighthouse-core/computed/js-bundles.js +11 -11
  126. package/lighthouse-core/computed/main-resource.js +2 -3
  127. package/lighthouse-core/computed/metrics/first-contentful-paint-all-frames.js +1 -1
  128. package/lighthouse-core/computed/metrics/first-contentful-paint.js +1 -1
  129. package/lighthouse-core/computed/metrics/first-meaningful-paint.js +1 -1
  130. package/lighthouse-core/computed/metrics/interactive.js +1 -1
  131. package/lighthouse-core/computed/metrics/lantern-first-contentful-paint.js +1 -1
  132. package/lighthouse-core/computed/metrics/lantern-first-meaningful-paint.js +1 -1
  133. package/lighthouse-core/computed/metrics/lantern-interactive.js +1 -1
  134. package/lighthouse-core/computed/metrics/lantern-largest-contentful-paint.js +1 -1
  135. package/lighthouse-core/computed/metrics/lantern-max-potential-fid.js +1 -1
  136. package/lighthouse-core/computed/metrics/lantern-metric.js +5 -3
  137. package/lighthouse-core/computed/metrics/lantern-speed-index.js +1 -1
  138. package/lighthouse-core/computed/metrics/lantern-total-blocking-time.js +1 -1
  139. package/lighthouse-core/computed/metrics/largest-contentful-paint-all-frames.js +1 -1
  140. package/lighthouse-core/computed/metrics/largest-contentful-paint.js +1 -1
  141. package/lighthouse-core/computed/metrics/max-potential-fid.js +1 -1
  142. package/lighthouse-core/computed/metrics/metric.js +0 -1
  143. package/lighthouse-core/computed/metrics/responsiveness.js +12 -9
  144. package/lighthouse-core/computed/metrics/speed-index.js +1 -1
  145. package/lighthouse-core/computed/metrics/timing-summary.js +6 -13
  146. package/lighthouse-core/computed/metrics/total-blocking-time.js +1 -1
  147. package/lighthouse-core/computed/module-duplication.js +5 -6
  148. package/lighthouse-core/computed/page-dependency-graph.js +28 -55
  149. package/lighthouse-core/computed/resource-summary.js +5 -5
  150. package/lighthouse-core/computed/unused-css.js +7 -6
  151. package/lighthouse-core/computed/unused-javascript-summary.js +36 -16
  152. package/lighthouse-core/config/budget.js +2 -2
  153. package/lighthouse-core/config/default-config.js +1 -2
  154. package/lighthouse-core/config/metrics-to-audits.js +5 -0
  155. package/lighthouse-core/fraggle-rock/api.js +1 -1
  156. package/lighthouse-core/fraggle-rock/config/default-config.js +8 -5
  157. package/lighthouse-core/fraggle-rock/gather/base-artifacts.js +3 -6
  158. package/lighthouse-core/fraggle-rock/gather/driver.js +2 -2
  159. package/lighthouse-core/fraggle-rock/gather/navigation-runner.js +26 -51
  160. package/lighthouse-core/fraggle-rock/gather/runner-helpers.js +3 -0
  161. package/lighthouse-core/fraggle-rock/gather/session.js +2 -2
  162. package/lighthouse-core/fraggle-rock/gather/snapshot-runner.js +4 -5
  163. package/lighthouse-core/fraggle-rock/gather/timespan-runner.js +6 -6
  164. package/lighthouse-core/gather/connections/cri.js +0 -1
  165. package/lighthouse-core/gather/driver/execution-context.js +2 -4
  166. package/lighthouse-core/gather/driver/navigation.js +9 -9
  167. package/lighthouse-core/gather/driver/network-monitor.js +3 -16
  168. package/lighthouse-core/gather/driver.js +1 -6
  169. package/lighthouse-core/gather/fetcher.js +210 -34
  170. package/lighthouse-core/gather/gather-runner.js +17 -13
  171. package/lighthouse-core/gather/gatherers/accessibility.js +4 -16
  172. package/lighthouse-core/gather/gatherers/console-messages.js +2 -4
  173. package/lighthouse-core/gather/gatherers/dobetterweb/doctype.js +2 -4
  174. package/lighthouse-core/gather/gatherers/full-page-screenshot.js +2 -3
  175. package/lighthouse-core/gather/gatherers/js-usage.js +87 -12
  176. package/lighthouse-core/gather/gatherers/link-elements.js +14 -12
  177. package/lighthouse-core/gather/gatherers/main-document-content.js +8 -8
  178. package/lighthouse-core/gather/gatherers/script-elements.js +56 -7
  179. package/lighthouse-core/gather/gatherers/seo/robots-txt.js +30 -2
  180. package/lighthouse-core/gather/gatherers/source-maps.js +1 -3
  181. package/lighthouse-core/gather/gatherers/trace-elements.js +21 -2
  182. package/lighthouse-core/gather/gatherers/web-app-manifest.js +2 -2
  183. package/lighthouse-core/index.js +2 -26
  184. package/lighthouse-core/lib/cdt/generated/SourceMap.js +1 -1
  185. package/lighthouse-core/lib/dependency-graph/simulator/network-analyzer.js +29 -8
  186. package/lighthouse-core/lib/navigation-error.js +4 -13
  187. package/lighthouse-core/lib/script-helpers.js +6 -11
  188. package/lighthouse-core/lib/url-shim.js +2 -2
  189. package/lighthouse-core/runner.js +5 -0
  190. package/lighthouse-core/scripts/manual-chrome-launcher.js +1 -0
  191. package/lighthouse-core/util-commonjs.js +24 -28
  192. package/package.json +12 -12
  193. package/readme.md +1 -1
  194. package/report/.eslintrc.cjs +1 -3
  195. package/report/assets/styles.css +10 -12
  196. package/report/assets/templates.html +9 -10
  197. package/report/clients/bundle.js +1 -0
  198. package/report/clients/standalone.js +1 -0
  199. package/report/generator/report-generator.js +21 -46
  200. package/report/renderer/api.js +1 -0
  201. package/report/renderer/category-renderer.js +1 -0
  202. package/report/renderer/components.js +304 -303
  203. package/report/renderer/crc-details-renderer.js +1 -0
  204. package/report/renderer/details-renderer.js +10 -10
  205. package/report/renderer/dom.js +1 -0
  206. package/report/renderer/drop-down-menu.js +1 -0
  207. package/report/renderer/element-screenshot-renderer.js +4 -0
  208. package/report/renderer/features-util.js +1 -0
  209. package/report/renderer/i18n.js +62 -118
  210. package/report/renderer/logger.js +1 -0
  211. package/report/renderer/open-tab.js +3 -1
  212. package/report/renderer/performance-category-renderer.js +1 -0
  213. package/report/renderer/pwa-category-renderer.js +1 -0
  214. package/report/renderer/report-renderer.js +1 -0
  215. package/report/renderer/report-ui-features.js +1 -0
  216. package/report/renderer/snippet-renderer.js +1 -0
  217. package/report/renderer/swap-locale-feature.js +1 -0
  218. package/report/renderer/text-encoding.js +1 -0
  219. package/report/renderer/topbar-features.js +1 -0
  220. package/report/renderer/util.js +24 -27
  221. package/report/test/clients/bundle-test.js +4 -0
  222. package/report/test/generator/file-namer-test.js +1 -0
  223. package/report/test/generator/report-generator-test.js +20 -25
  224. package/report/test/renderer/category-renderer-test.js +3 -0
  225. package/report/test/renderer/components-test.js +3 -0
  226. package/report/test/renderer/crc-details-renderer-test.js +3 -0
  227. package/report/test/renderer/details-renderer-test.js +12 -58
  228. package/report/test/renderer/dom-test.js +3 -0
  229. package/report/test/renderer/element-screenshot-renderer-test.js +6 -3
  230. package/report/test/renderer/i18n-test.js +25 -70
  231. package/report/test/renderer/performance-category-renderer-test.js +4 -11
  232. package/report/test/renderer/pwa-category-renderer-test.js +3 -0
  233. package/report/test/renderer/report-renderer-axe-test.js +3 -0
  234. package/report/test/renderer/report-renderer-test.js +3 -0
  235. package/report/test/renderer/report-ui-features-test.js +3 -0
  236. package/report/test/renderer/snippet-renderer-test.js +3 -0
  237. package/report/test/renderer/text-encoding-test.js +3 -0
  238. package/report/test/renderer/util-test.js +5 -2
  239. package/report/test-assets/faux-psi.js +1 -2
  240. package/shared/localization/locales/en-US.json +260 -53
  241. package/shared/localization/locales/en-XL.json +260 -53
  242. package/shared/test/localization/format-test.js +2 -0
  243. package/shared/test/localization/locales-test.js +2 -0
  244. package/shared/test/localization/swap-locale-test.js +2 -0
  245. package/third-party/chromium-synchronization/inspector-issueAdded-types-test.js +2 -0
  246. package/third-party/chromium-synchronization/installability-errors-test.js +2 -0
  247. package/tsconfig.json +0 -1
  248. package/types/artifacts.d.ts +9 -48
  249. package/types/config.d.ts +0 -2
  250. package/types/externs.d.ts +2 -2
  251. package/types/gatherer.d.ts +2 -1
  252. package/types/global-lh.d.ts +0 -3
  253. package/types/lhr/audit-details.d.ts +3 -1
  254. package/types/lhr/lhr.d.ts +2 -2
  255. package/types/lhr/treemap.d.ts +1 -0
  256. package/lighthouse-core/audits/script-elements-test-audit.js +0 -30
  257. package/lighthouse-core/gather/gatherers/scripts.js +0 -154
  258. package/report/test/.eslintrc.cjs +0 -11
  259. package/shared/test/localization/.eslintrc.cjs +0 -11
@@ -30,7 +30,7 @@ const UIStrings = {
30
30
  // eslint-disable-next-line max-len
31
31
  // TODO: web.dev article. this codelab is good starting place: https://web.dev/codelab-serve-modern-code/
32
32
  /** Description of a Lighthouse audit that tells the user about old JavaScript that is no longer needed. This is displayed after a user expands the section to see more. No character length limits. 'Learn More' becomes link text to additional documentation. */
33
- description: 'Polyfills and transforms enable legacy browsers to use new JavaScript features. However, many aren\'t necessary for modern browsers. For your bundled JavaScript, adopt a modern script deployment strategy using module/nomodule feature detection to reduce the amount of code shipped to modern browsers, while retaining support for legacy browsers. [Learn More](https://web.dev/publish-modern-javascript/)',
33
+ description: 'Polyfills and transforms enable legacy browsers to use new JavaScript features. However, many aren\'t necessary for modern browsers. For your bundled JavaScript, adopt a modern script deployment strategy using module/nomodule feature detection to reduce the amount of code shipped to modern browsers, while retaining support for legacy browsers. [Learn More](https://philipwalton.com/articles/deploying-es2015-code-in-production-today/)',
34
34
  };
35
35
 
36
36
  const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
@@ -109,7 +109,7 @@ class LegacyJavascript extends ByteEfficiencyAudit {
109
109
  scoreDisplayMode: ByteEfficiencyAudit.SCORING_MODES.NUMERIC,
110
110
  description: str_(UIStrings.description),
111
111
  title: str_(UIStrings.title),
112
- requiredArtifacts: ['devtoolsLogs', 'traces', 'Scripts', 'SourceMaps',
112
+ requiredArtifacts: ['devtoolsLogs', 'traces', 'ScriptElements', 'SourceMaps',
113
113
  'GatherContext', 'URL'],
114
114
  };
115
115
  }
@@ -274,24 +274,26 @@ class LegacyJavascript extends ByteEfficiencyAudit {
274
274
  * Returns a collection of match results grouped by script url.
275
275
  *
276
276
  * @param {CodePatternMatcher} matcher
277
- * @param {LH.Artifacts['Scripts']} scripts
277
+ * @param {LH.GathererArtifacts['ScriptElements']} scripts
278
278
  * @param {LH.Artifacts.NetworkRequest[]} networkRecords
279
279
  * @param {LH.Artifacts.Bundle[]} bundles
280
- * @return {Map<LH.Artifacts.Script, PatternMatchResult[]>}
280
+ * @return {Map<string, PatternMatchResult[]>}
281
281
  */
282
282
  static detectAcrossScripts(matcher, scripts, networkRecords, bundles) {
283
- /** @type {Map<LH.Artifacts.Script, PatternMatchResult[]>} */
284
- const scriptToMatchResults = new Map();
283
+ /** @type {Map<string, PatternMatchResult[]>} */
284
+ const urlToMatchResults = new Map();
285
285
  const polyfillData = this.getPolyfillData();
286
286
 
287
- for (const script of Object.values(scripts)) {
288
- if (!script.content) continue;
287
+ for (const {requestId, content} of Object.values(scripts)) {
288
+ if (!content) continue;
289
+ const networkRecord = networkRecords.find(record => record.requestId === requestId);
290
+ if (!networkRecord) continue;
289
291
 
290
292
  // Start with pattern matching against the downloaded script.
291
- const matches = matcher.match(script.content);
293
+ const matches = matcher.match(content);
292
294
 
293
295
  // If it's a bundle with source maps, add in the polyfill modules by name too.
294
- const bundle = bundles.find(b => b.script.scriptId === script.scriptId);
296
+ const bundle = bundles.find(b => b.script.src === networkRecord.url);
295
297
  if (bundle) {
296
298
  for (const {coreJs2Module, coreJs3Module, name} of polyfillData) {
297
299
  // Skip if the pattern matching found a match for this polyfill.
@@ -311,10 +313,10 @@ class LegacyJavascript extends ByteEfficiencyAudit {
311
313
  }
312
314
 
313
315
  if (!matches.length) continue;
314
- scriptToMatchResults.set(script, matches);
316
+ urlToMatchResults.set(networkRecord.url, matches);
315
317
  }
316
318
 
317
- return scriptToMatchResults;
319
+ return urlToMatchResults;
318
320
  }
319
321
 
320
322
  /**
@@ -371,14 +373,14 @@ class LegacyJavascript extends ByteEfficiencyAudit {
371
373
  let transferRatio = transferRatioByUrl.get(url);
372
374
  if (transferRatio !== undefined) return transferRatio;
373
375
 
374
- const script = artifacts.Scripts.find(script => script.url === url);
376
+ const script = artifacts.ScriptElements.find(script => script.src === url);
377
+ const networkRecord = getRequestForScript(networkRecords, script);
375
378
 
376
379
  if (!script || script.content === null) {
377
380
  // Can't find content, so just use 1.
378
381
  transferRatio = 1;
379
382
  } else {
380
- const networkRecord = getRequestForScript(networkRecords, script);
381
- const contentLength = script.length || 0;
383
+ const contentLength = script.content.length;
382
384
  const transferSize =
383
385
  ByteEfficiencyAudit.estimateTransferSize(networkRecord, contentLength, 'Script');
384
386
  transferRatio = transferSize / contentLength;
@@ -409,15 +411,15 @@ class LegacyJavascript extends ByteEfficiencyAudit {
409
411
  /** @type {Map<string, number>} */
410
412
  const transferRatioByUrl = new Map();
411
413
 
412
- const scriptToMatchResults =
413
- this.detectAcrossScripts(matcher, artifacts.Scripts, networkRecords, bundles);
414
- for (const [script, matches] of scriptToMatchResults.entries()) {
414
+ const urlToMatchResults =
415
+ this.detectAcrossScripts(matcher, artifacts.ScriptElements, networkRecords, bundles);
416
+ for (const [url, matches] of urlToMatchResults.entries()) {
415
417
  const transferRatio = await this.estimateTransferRatioForScript(
416
- transferRatioByUrl, script.url, artifacts, networkRecords);
418
+ transferRatioByUrl, url, artifacts, networkRecords);
417
419
  const wastedBytes = Math.round(this.estimateWastedBytes(matches) * transferRatio);
418
420
  /** @type {typeof items[number]} */
419
421
  const item = {
420
- url: script.url,
422
+ url,
421
423
  wastedBytes,
422
424
  subItems: {
423
425
  type: 'subitems',
@@ -427,13 +429,13 @@ class LegacyJavascript extends ByteEfficiencyAudit {
427
429
  totalBytes: 0,
428
430
  };
429
431
 
430
- const bundle = bundles.find(bundle => bundle.script.scriptId === script.scriptId);
432
+ const bundle = bundles.find(bundle => bundle.script.src === url);
431
433
  for (const match of matches) {
432
434
  const {name, line, column} = match;
433
435
  /** @type {SubItem} */
434
436
  const subItem = {
435
437
  signal: name,
436
- location: ByteEfficiencyAudit.makeSourceLocation(script.url, line, column, bundle),
438
+ location: ByteEfficiencyAudit.makeSourceLocation(url, line, column, bundle),
437
439
  };
438
440
  item.subItems.items.push(subItem);
439
441
  }
@@ -51,7 +51,7 @@ class OffscreenImages extends ByteEfficiencyAudit {
51
51
  scoreDisplayMode: ByteEfficiencyAudit.SCORING_MODES.NUMERIC,
52
52
  supportedModes: ['navigation'],
53
53
  requiredArtifacts: ['ImageElements', 'ViewportDimensions', 'GatherContext', 'devtoolsLogs',
54
- 'traces', 'URL'],
54
+ 'traces'],
55
55
  };
56
56
  }
57
57
 
@@ -182,7 +182,6 @@ class OffscreenImages extends ByteEfficiencyAudit {
182
182
  const gatherContext = artifacts.GatherContext;
183
183
  const trace = artifacts.traces[ByteEfficiencyAudit.DEFAULT_PASS];
184
184
  const devtoolsLog = artifacts.devtoolsLogs[ByteEfficiencyAudit.DEFAULT_PASS];
185
- const URL = artifacts.URL;
186
185
 
187
186
  /** @type {string[]} */
188
187
  const warnings = [];
@@ -213,7 +212,7 @@ class OffscreenImages extends ByteEfficiencyAudit {
213
212
  const unfilteredResults = Array.from(resultsMap.values());
214
213
  // get the interactive time or fallback to getting the end of trace time
215
214
  try {
216
- const metricComputationData = {trace, devtoolsLog, gatherContext, settings, URL};
215
+ const metricComputationData = {trace, devtoolsLog, gatherContext, settings};
217
216
  const interactive = await Interactive.request(metricComputationData, context);
218
217
 
219
218
  // use interactive to generate items
@@ -145,7 +145,7 @@ class RenderBlockingResources extends Audit {
145
145
  };
146
146
 
147
147
  const metricComputationData = {trace, devtoolsLog, gatherContext, simulator,
148
- settings: metricSettings, URL: artifacts.URL};
148
+ settings: metricSettings};
149
149
 
150
150
  // Cast to just `LanternMetric` since we explicitly set `throttlingMethod: 'simulate'`.
151
151
  const fcpSimulation = /** @type {LH.Artifacts.LanternMetric} */
@@ -262,12 +262,13 @@ class RenderBlockingResources extends Audit {
262
262
  try {
263
263
  const unusedCssItems = await UnusedCSS.request({
264
264
  CSSUsage: artifacts.CSSUsage,
265
+ URL: artifacts.URL,
265
266
  devtoolsLog: artifacts.devtoolsLogs[Audit.DEFAULT_PASS],
266
267
  }, context);
267
268
  for (const item of unusedCssItems) {
268
269
  wastedBytesByUrl.set(item.url, item.wastedBytes);
269
270
  }
270
- } catch {}
271
+ } catch (_) {}
271
272
 
272
273
  return wastedBytesByUrl;
273
274
  }
@@ -53,14 +53,15 @@ class UnminifiedCSS extends ByteEfficiencyAudit {
53
53
  /**
54
54
  * @param {LH.Artifacts.CSSStyleSheetInfo} stylesheet
55
55
  * @param {LH.Artifacts.NetworkRequest|undefined} networkRecord
56
+ * @param {string} pageUrl
56
57
  * @return {{url: string, totalBytes: number, wastedBytes: number, wastedPercent: number}}
57
58
  */
58
- static computeWaste(stylesheet, networkRecord) {
59
+ static computeWaste(stylesheet, networkRecord, pageUrl) {
59
60
  const content = stylesheet.content;
60
61
  const totalTokenLength = UnminifiedCSS.computeTokenLength(content);
61
62
 
62
63
  let url = stylesheet.header.sourceURL;
63
- if (!url || stylesheet.header.isInline) {
64
+ if (!url || url === pageUrl) {
64
65
  const contentPreview = UnusedCSS.determineContentPreview(stylesheet.content);
65
66
  url = contentPreview;
66
67
  }
@@ -84,13 +85,14 @@ class UnminifiedCSS extends ByteEfficiencyAudit {
84
85
  * @return {ByteEfficiencyAudit.ByteEfficiencyProduct}
85
86
  */
86
87
  static audit_(artifacts, networkRecords) {
88
+ const pageUrl = artifacts.URL.finalUrl;
87
89
  const items = [];
88
90
  for (const stylesheet of artifacts.CSSUsage.stylesheets) {
89
91
  const networkRecord = networkRecords
90
92
  .find(record => record.url === stylesheet.header.sourceURL);
91
93
  if (!stylesheet.content) continue;
92
94
 
93
- const result = UnminifiedCSS.computeWaste(stylesheet, networkRecord);
95
+ const result = UnminifiedCSS.computeWaste(stylesheet, networkRecord, pageUrl);
94
96
 
95
97
  // If the ratio is minimal, the file is likely already minified, so ignore it.
96
98
  // If the total number of bytes to be saved is quite small, it's also safe to ignore.
@@ -8,7 +8,7 @@
8
8
  const ByteEfficiencyAudit = require('./byte-efficiency-audit.js');
9
9
  const i18n = require('../../lib/i18n/i18n.js');
10
10
  const computeTokenLength = require('../../lib/minification-estimator.js').computeJSTokenLength;
11
- const {getRequestForScript, isInline} = require('../../lib/script-helpers.js');
11
+ const {getRequestForScript} = require('../../lib/script-helpers.js');
12
12
 
13
13
  const UIStrings = {
14
14
  /** Imperative title of a Lighthouse audit that tells the user to minify the page’s JS code to reduce file size. This is displayed in a list of audit titles that Lighthouse generates. */
@@ -43,7 +43,7 @@ class UnminifiedJavaScript extends ByteEfficiencyAudit {
43
43
  title: str_(UIStrings.title),
44
44
  description: str_(UIStrings.description),
45
45
  scoreDisplayMode: ByteEfficiencyAudit.SCORING_MODES.NUMERIC,
46
- requiredArtifacts: ['Scripts', 'devtoolsLogs', 'traces', 'GatherContext', 'URL'],
46
+ requiredArtifacts: ['ScriptElements', 'devtoolsLogs', 'traces', 'GatherContext'],
47
47
  };
48
48
  }
49
49
 
@@ -79,16 +79,16 @@ class UnminifiedJavaScript extends ByteEfficiencyAudit {
79
79
  /** @type {Array<LH.Audit.ByteEfficiencyItem>} */
80
80
  const items = [];
81
81
  const warnings = [];
82
- for (const script of artifacts.Scripts) {
83
- if (!script.content) continue;
82
+ for (const script of artifacts.ScriptElements) {
83
+ const {src, content} = script;
84
+ if (!content) continue;
84
85
 
85
86
  const networkRecord = getRequestForScript(networkRecords, script);
86
-
87
- const displayUrl = isInline(script) ?
88
- `inline: ${script.content.substring(0, 40)}...` :
89
- script.url;
87
+ const displayUrl = !src || !networkRecord ?
88
+ `inline: ${content.substr(0, 40)}...` :
89
+ networkRecord.url;
90
90
  try {
91
- const result = UnminifiedJavaScript.computeWaste(script.content, displayUrl, networkRecord);
91
+ const result = UnminifiedJavaScript.computeWaste(content, displayUrl, networkRecord);
92
92
  // If the ratio is minimal, the file is likely already minified, so ignore it.
93
93
  // If the total number of bytes to be saved is quite small, it's also safe to ignore.
94
94
  if (result.wastedPercent < IGNORE_THRESHOLD_IN_PERCENT ||
@@ -96,7 +96,8 @@ class UnminifiedJavaScript extends ByteEfficiencyAudit {
96
96
  !Number.isFinite(result.wastedBytes)) continue;
97
97
  items.push(result);
98
98
  } catch (err) {
99
- warnings.push(`Unable to process script ${script.url}: ${err.message}`);
99
+ const url = networkRecord ? networkRecord.url : '?';
100
+ warnings.push(`Unable to process script ${url}: ${err.message}`);
100
101
  }
101
102
  }
102
103
 
@@ -47,6 +47,7 @@ class UnusedCSSRules extends ByteEfficiencyAudit {
47
47
  static async audit_(artifacts, _, context) {
48
48
  const unusedCssItems = await UnusedCSS.request({
49
49
  CSSUsage: artifacts.CSSUsage,
50
+ URL: artifacts.URL,
50
51
  devtoolsLog: artifacts.devtoolsLogs[ByteEfficiencyAudit.DEFAULT_PASS],
51
52
  }, context);
52
53
  const items = unusedCssItems
@@ -68,8 +68,8 @@ class UnusedJavaScript extends ByteEfficiencyAudit {
68
68
  title: str_(UIStrings.title),
69
69
  description: str_(UIStrings.description),
70
70
  scoreDisplayMode: ByteEfficiencyAudit.SCORING_MODES.NUMERIC,
71
- requiredArtifacts: ['JsUsage', 'Scripts', 'SourceMaps', 'GatherContext',
72
- 'devtoolsLogs', 'traces', 'URL'],
71
+ requiredArtifacts: ['JsUsage', 'ScriptElements', 'SourceMaps', 'GatherContext',
72
+ 'devtoolsLogs', 'traces'],
73
73
  };
74
74
  }
75
75
 
@@ -87,16 +87,13 @@ class UnusedJavaScript extends ByteEfficiencyAudit {
87
87
  } = context.options || {};
88
88
 
89
89
  const items = [];
90
- for (const [scriptId, scriptCoverage] of Object.entries(artifacts.JsUsage)) {
91
- const script = artifacts.Scripts.find(s => s.scriptId === scriptId);
92
- if (!script) continue; // This should never happen.
93
-
94
- const networkRecord = getRequestForScript(networkRecords, script);
90
+ for (const [url, scriptCoverages] of Object.entries(artifacts.JsUsage)) {
91
+ const fakeScript = /** @type {LH.Artifacts.ScriptElement} */ ({src: url});
92
+ const networkRecord = getRequestForScript(networkRecords, fakeScript);
95
93
  if (!networkRecord) continue;
96
-
97
- const bundle = bundles.find(b => b.script.scriptId === scriptId);
94
+ const bundle = bundles.find(b => b.script.src === url);
98
95
  const unusedJsSummary =
99
- await UnusedJavaScriptSummary.request({scriptId, scriptCoverage, bundle}, context);
96
+ await UnusedJavaScriptSummary.request({url, scriptCoverages, bundle}, context);
100
97
  if (unusedJsSummary.wastedBytes === 0 || unusedJsSummary.totalBytes === 0) continue;
101
98
 
102
99
  const transfer = ByteEfficiencyAudit
@@ -104,7 +101,7 @@ class UnusedJavaScript extends ByteEfficiencyAudit {
104
101
  const transferRatio = transfer / unusedJsSummary.totalBytes;
105
102
  /** @type {LH.Audit.ByteEfficiencyItem} */
106
103
  const item = {
107
- url: script.url,
104
+ url: unusedJsSummary.url,
108
105
  totalBytes: Math.round(transferRatio * unusedJsSummary.totalBytes),
109
106
  wastedBytes: Math.round(transferRatio * unusedJsSummary.wastedBytes),
110
107
  wastedPercent: unusedJsSummary.wastedPercent,
@@ -44,7 +44,7 @@ class UsesResponsiveImages extends ByteEfficiencyAudit {
44
44
  description: str_(UIStrings.description),
45
45
  scoreDisplayMode: ByteEfficiencyAudit.SCORING_MODES.NUMERIC,
46
46
  requiredArtifacts: ['ImageElements', 'ViewportDimensions', 'GatherContext',
47
- 'devtoolsLogs', 'traces', 'URL'],
47
+ 'devtoolsLogs', 'traces'],
48
48
  };
49
49
  }
50
50
 
@@ -37,7 +37,7 @@ class ResponsesAreCompressed extends ByteEfficiencyAudit {
37
37
  title: str_(UIStrings.title),
38
38
  description: str_(UIStrings.description),
39
39
  scoreDisplayMode: ByteEfficiencyAudit.SCORING_MODES.NUMERIC,
40
- requiredArtifacts: ['ResponseCompression', 'GatherContext', 'devtoolsLogs', 'traces', 'URL'],
40
+ requiredArtifacts: ['ResponseCompression', 'GatherContext', 'devtoolsLogs', 'traces'],
41
41
  };
42
42
  }
43
43