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.
- package/changelog.md +70 -0
- package/dist/report/bundle.esm.js +400 -808
- package/dist/report/flow.js +22 -27
- package/dist/report/standalone.js +18 -23
- package/flow-report/src/summary/category.tsx +1 -1
- package/jest.config.js +1 -1
- package/lighthouse-cli/.eslintrc.cjs +4 -3
- package/lighthouse-cli/bin.js +1 -0
- package/lighthouse-cli/cli-flags.js +4 -3
- package/lighthouse-cli/commands/commands.js +1 -0
- package/lighthouse-cli/commands/list-audits.js +1 -0
- package/lighthouse-cli/commands/list-locales.js +1 -0
- package/lighthouse-cli/commands/list-trace-categories.js +1 -0
- package/lighthouse-cli/index.js +1 -0
- package/lighthouse-cli/printer.js +1 -0
- package/lighthouse-cli/run.js +24 -9
- package/lighthouse-cli/sentry-prompt.js +1 -0
- package/lighthouse-cli/test/smokehouse/core-tests.js +1 -0
- package/lighthouse-cli/test/smokehouse/frontends/back-compat-util.js +1 -0
- package/lighthouse-cli/test/smokehouse/frontends/lib.js +1 -0
- package/lighthouse-cli/test/smokehouse/frontends/node.js +1 -0
- package/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js +1 -0
- package/lighthouse-cli/test/smokehouse/lib/child-process-error.js +1 -0
- package/lighthouse-cli/test/smokehouse/lib/concurrent-mapper.js +1 -0
- package/lighthouse-cli/test/smokehouse/lib/local-console.js +1 -0
- package/lighthouse-cli/test/smokehouse/lighthouse-runners/bundle.js +23 -109
- package/lighthouse-cli/test/smokehouse/lighthouse-runners/cli.js +3 -2
- package/lighthouse-cli/test/smokehouse/lighthouse-runners/devtools.js +19 -28
- package/lighthouse-cli/test/smokehouse/report-assert.js +4 -3
- package/lighthouse-cli/test/smokehouse/smokehouse.js +1 -1
- package/lighthouse-cli/test/smokehouse/version-check-test.js +3 -0
- package/lighthouse-cli/test/smokehouse/version-check.js +1 -0
- package/lighthouse-core/audits/accessibility/accesskeys.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-allowed-attr.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-command-name.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-hidden-body.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-hidden-focus.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-input-field-name.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-meter-name.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-progressbar-name.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-required-attr.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-required-children.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-required-parent.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-roles.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-toggle-field-name.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-tooltip-name.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-treeitem-name.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-valid-attr-value.js +1 -1
- package/lighthouse-core/audits/accessibility/aria-valid-attr.js +1 -1
- package/lighthouse-core/audits/accessibility/button-name.js +1 -1
- package/lighthouse-core/audits/accessibility/bypass.js +1 -1
- package/lighthouse-core/audits/accessibility/color-contrast.js +1 -1
- package/lighthouse-core/audits/accessibility/definition-list.js +1 -1
- package/lighthouse-core/audits/accessibility/dlitem.js +1 -1
- package/lighthouse-core/audits/accessibility/document-title.js +1 -1
- package/lighthouse-core/audits/accessibility/duplicate-id-active.js +1 -1
- package/lighthouse-core/audits/accessibility/duplicate-id-aria.js +1 -1
- package/lighthouse-core/audits/accessibility/form-field-multiple-labels.js +1 -1
- package/lighthouse-core/audits/accessibility/frame-title.js +1 -1
- package/lighthouse-core/audits/accessibility/heading-order.js +1 -1
- package/lighthouse-core/audits/accessibility/html-has-lang.js +1 -1
- package/lighthouse-core/audits/accessibility/html-lang-valid.js +1 -1
- package/lighthouse-core/audits/accessibility/image-alt.js +1 -1
- package/lighthouse-core/audits/accessibility/input-image-alt.js +1 -1
- package/lighthouse-core/audits/accessibility/label.js +1 -1
- package/lighthouse-core/audits/accessibility/link-name.js +1 -1
- package/lighthouse-core/audits/accessibility/list.js +1 -1
- package/lighthouse-core/audits/accessibility/listitem.js +5 -5
- package/lighthouse-core/audits/accessibility/meta-refresh.js +1 -1
- package/lighthouse-core/audits/accessibility/meta-viewport.js +1 -1
- package/lighthouse-core/audits/accessibility/object-alt.js +1 -1
- package/lighthouse-core/audits/accessibility/tabindex.js +1 -1
- package/lighthouse-core/audits/accessibility/td-headers-attr.js +1 -1
- package/lighthouse-core/audits/accessibility/th-has-data-cells.js +1 -1
- package/lighthouse-core/audits/accessibility/valid-lang.js +1 -1
- package/lighthouse-core/audits/accessibility/video-caption.js +1 -1
- package/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js +1 -2
- package/lighthouse-core/audits/byte-efficiency/duplicated-javascript.js +12 -11
- package/lighthouse-core/audits/byte-efficiency/efficient-animated-content.js +1 -1
- package/lighthouse-core/audits/byte-efficiency/legacy-javascript.js +24 -22
- package/lighthouse-core/audits/byte-efficiency/offscreen-images.js +2 -3
- package/lighthouse-core/audits/byte-efficiency/render-blocking-resources.js +3 -2
- package/lighthouse-core/audits/byte-efficiency/unminified-css.js +5 -3
- package/lighthouse-core/audits/byte-efficiency/unminified-javascript.js +11 -10
- package/lighthouse-core/audits/byte-efficiency/unused-css-rules.js +1 -0
- package/lighthouse-core/audits/byte-efficiency/unused-javascript.js +8 -11
- package/lighthouse-core/audits/byte-efficiency/uses-responsive-images.js +1 -1
- package/lighthouse-core/audits/byte-efficiency/uses-text-compression.js +1 -1
- package/lighthouse-core/audits/deprecations.js +598 -8
- package/lighthouse-core/audits/diagnostics.js +3 -4
- package/lighthouse-core/audits/dobetterweb/doctype.js +9 -20
- package/lighthouse-core/audits/dobetterweb/geolocation-on-start.js +1 -1
- package/lighthouse-core/audits/dobetterweb/no-document-write.js +1 -1
- package/lighthouse-core/audits/dobetterweb/notification-on-start.js +1 -1
- package/lighthouse-core/audits/dobetterweb/uses-http2.js +1 -2
- package/lighthouse-core/audits/dobetterweb/uses-passive-event-listeners.js +1 -1
- package/lighthouse-core/audits/errors-in-console.js +2 -2
- package/lighthouse-core/audits/long-tasks.js +2 -3
- package/lighthouse-core/audits/metrics/experimental-interaction-to-next-paint.js +3 -1
- package/lighthouse-core/audits/metrics/first-contentful-paint-3g.js +2 -2
- package/lighthouse-core/audits/metrics/first-contentful-paint.js +2 -3
- package/lighthouse-core/audits/metrics/first-meaningful-paint.js +2 -3
- package/lighthouse-core/audits/metrics/interactive.js +2 -3
- package/lighthouse-core/audits/metrics/largest-contentful-paint.js +2 -3
- package/lighthouse-core/audits/metrics/max-potential-fid.js +2 -3
- package/lighthouse-core/audits/metrics/speed-index.js +2 -3
- package/lighthouse-core/audits/metrics/total-blocking-time.js +2 -3
- package/lighthouse-core/audits/metrics.js +2 -3
- package/lighthouse-core/audits/no-unload-listeners.js +15 -7
- package/lighthouse-core/audits/predictive-perf.js +1 -2
- package/lighthouse-core/audits/preload-lcp-image.js +3 -3
- package/lighthouse-core/audits/redirects.js +1 -1
- package/lighthouse-core/audits/script-treemap-data.js +45 -45
- package/lighthouse-core/audits/seo/http-status-code.js +4 -2
- package/lighthouse-core/audits/seo/link-text.js +0 -2
- package/lighthouse-core/audits/server-response-time.js +17 -2
- package/lighthouse-core/audits/service-worker.js +2 -7
- package/lighthouse-core/audits/timing-budget.js +2 -3
- package/lighthouse-core/audits/uses-rel-preconnect.js +1 -1
- package/lighthouse-core/audits/uses-rel-preload.js +1 -1
- package/lighthouse-core/audits/valid-source-maps.js +14 -12
- package/lighthouse-core/audits/violation-audit.js +1 -1
- package/lighthouse-core/audits/work-during-interaction.js +280 -0
- package/lighthouse-core/computed/critical-request-chains.js +9 -5
- package/lighthouse-core/computed/js-bundles.js +11 -11
- package/lighthouse-core/computed/main-resource.js +2 -3
- package/lighthouse-core/computed/metrics/first-contentful-paint-all-frames.js +1 -1
- package/lighthouse-core/computed/metrics/first-contentful-paint.js +1 -1
- package/lighthouse-core/computed/metrics/first-meaningful-paint.js +1 -1
- package/lighthouse-core/computed/metrics/interactive.js +1 -1
- package/lighthouse-core/computed/metrics/lantern-first-contentful-paint.js +1 -1
- package/lighthouse-core/computed/metrics/lantern-first-meaningful-paint.js +1 -1
- package/lighthouse-core/computed/metrics/lantern-interactive.js +1 -1
- package/lighthouse-core/computed/metrics/lantern-largest-contentful-paint.js +1 -1
- package/lighthouse-core/computed/metrics/lantern-max-potential-fid.js +1 -1
- package/lighthouse-core/computed/metrics/lantern-metric.js +5 -3
- package/lighthouse-core/computed/metrics/lantern-speed-index.js +1 -1
- package/lighthouse-core/computed/metrics/lantern-total-blocking-time.js +1 -1
- package/lighthouse-core/computed/metrics/largest-contentful-paint-all-frames.js +1 -1
- package/lighthouse-core/computed/metrics/largest-contentful-paint.js +1 -1
- package/lighthouse-core/computed/metrics/max-potential-fid.js +1 -1
- package/lighthouse-core/computed/metrics/metric.js +0 -1
- package/lighthouse-core/computed/metrics/responsiveness.js +12 -9
- package/lighthouse-core/computed/metrics/speed-index.js +1 -1
- package/lighthouse-core/computed/metrics/timing-summary.js +6 -13
- package/lighthouse-core/computed/metrics/total-blocking-time.js +1 -1
- package/lighthouse-core/computed/module-duplication.js +5 -6
- package/lighthouse-core/computed/page-dependency-graph.js +28 -55
- package/lighthouse-core/computed/resource-summary.js +5 -5
- package/lighthouse-core/computed/unused-css.js +7 -6
- package/lighthouse-core/computed/unused-javascript-summary.js +36 -16
- package/lighthouse-core/config/budget.js +2 -2
- package/lighthouse-core/config/default-config.js +1 -2
- package/lighthouse-core/config/metrics-to-audits.js +5 -0
- package/lighthouse-core/fraggle-rock/api.js +1 -1
- package/lighthouse-core/fraggle-rock/config/default-config.js +8 -5
- package/lighthouse-core/fraggle-rock/gather/base-artifacts.js +3 -6
- package/lighthouse-core/fraggle-rock/gather/driver.js +2 -2
- package/lighthouse-core/fraggle-rock/gather/navigation-runner.js +26 -51
- package/lighthouse-core/fraggle-rock/gather/runner-helpers.js +3 -0
- package/lighthouse-core/fraggle-rock/gather/session.js +2 -2
- package/lighthouse-core/fraggle-rock/gather/snapshot-runner.js +4 -5
- package/lighthouse-core/fraggle-rock/gather/timespan-runner.js +6 -6
- package/lighthouse-core/gather/connections/cri.js +0 -1
- package/lighthouse-core/gather/driver/execution-context.js +2 -4
- package/lighthouse-core/gather/driver/navigation.js +9 -9
- package/lighthouse-core/gather/driver/network-monitor.js +3 -16
- package/lighthouse-core/gather/driver.js +1 -6
- package/lighthouse-core/gather/fetcher.js +210 -34
- package/lighthouse-core/gather/gather-runner.js +17 -13
- package/lighthouse-core/gather/gatherers/accessibility.js +4 -16
- package/lighthouse-core/gather/gatherers/console-messages.js +2 -4
- package/lighthouse-core/gather/gatherers/dobetterweb/doctype.js +2 -4
- package/lighthouse-core/gather/gatherers/full-page-screenshot.js +2 -3
- package/lighthouse-core/gather/gatherers/js-usage.js +87 -12
- package/lighthouse-core/gather/gatherers/link-elements.js +14 -12
- package/lighthouse-core/gather/gatherers/main-document-content.js +8 -8
- package/lighthouse-core/gather/gatherers/script-elements.js +56 -7
- package/lighthouse-core/gather/gatherers/seo/robots-txt.js +30 -2
- package/lighthouse-core/gather/gatherers/source-maps.js +1 -3
- package/lighthouse-core/gather/gatherers/trace-elements.js +21 -2
- package/lighthouse-core/gather/gatherers/web-app-manifest.js +2 -2
- package/lighthouse-core/index.js +2 -26
- package/lighthouse-core/lib/cdt/generated/SourceMap.js +1 -1
- package/lighthouse-core/lib/dependency-graph/simulator/network-analyzer.js +29 -8
- package/lighthouse-core/lib/navigation-error.js +4 -13
- package/lighthouse-core/lib/script-helpers.js +6 -11
- package/lighthouse-core/lib/url-shim.js +2 -2
- package/lighthouse-core/runner.js +5 -0
- package/lighthouse-core/scripts/manual-chrome-launcher.js +1 -0
- package/lighthouse-core/util-commonjs.js +24 -28
- package/package.json +12 -12
- package/readme.md +1 -1
- package/report/.eslintrc.cjs +1 -3
- package/report/assets/styles.css +10 -12
- package/report/assets/templates.html +9 -10
- package/report/clients/bundle.js +1 -0
- package/report/clients/standalone.js +1 -0
- package/report/generator/report-generator.js +21 -46
- package/report/renderer/api.js +1 -0
- package/report/renderer/category-renderer.js +1 -0
- package/report/renderer/components.js +304 -303
- package/report/renderer/crc-details-renderer.js +1 -0
- package/report/renderer/details-renderer.js +10 -10
- package/report/renderer/dom.js +1 -0
- package/report/renderer/drop-down-menu.js +1 -0
- package/report/renderer/element-screenshot-renderer.js +4 -0
- package/report/renderer/features-util.js +1 -0
- package/report/renderer/i18n.js +62 -118
- package/report/renderer/logger.js +1 -0
- package/report/renderer/open-tab.js +3 -1
- package/report/renderer/performance-category-renderer.js +1 -0
- package/report/renderer/pwa-category-renderer.js +1 -0
- package/report/renderer/report-renderer.js +1 -0
- package/report/renderer/report-ui-features.js +1 -0
- package/report/renderer/snippet-renderer.js +1 -0
- package/report/renderer/swap-locale-feature.js +1 -0
- package/report/renderer/text-encoding.js +1 -0
- package/report/renderer/topbar-features.js +1 -0
- package/report/renderer/util.js +24 -27
- package/report/test/clients/bundle-test.js +4 -0
- package/report/test/generator/file-namer-test.js +1 -0
- package/report/test/generator/report-generator-test.js +20 -25
- package/report/test/renderer/category-renderer-test.js +3 -0
- package/report/test/renderer/components-test.js +3 -0
- package/report/test/renderer/crc-details-renderer-test.js +3 -0
- package/report/test/renderer/details-renderer-test.js +12 -58
- package/report/test/renderer/dom-test.js +3 -0
- package/report/test/renderer/element-screenshot-renderer-test.js +6 -3
- package/report/test/renderer/i18n-test.js +25 -70
- package/report/test/renderer/performance-category-renderer-test.js +4 -11
- package/report/test/renderer/pwa-category-renderer-test.js +3 -0
- package/report/test/renderer/report-renderer-axe-test.js +3 -0
- package/report/test/renderer/report-renderer-test.js +3 -0
- package/report/test/renderer/report-ui-features-test.js +3 -0
- package/report/test/renderer/snippet-renderer-test.js +3 -0
- package/report/test/renderer/text-encoding-test.js +3 -0
- package/report/test/renderer/util-test.js +5 -2
- package/report/test-assets/faux-psi.js +1 -2
- package/shared/localization/locales/en-US.json +260 -53
- package/shared/localization/locales/en-XL.json +260 -53
- package/shared/test/localization/format-test.js +2 -0
- package/shared/test/localization/locales-test.js +2 -0
- package/shared/test/localization/swap-locale-test.js +2 -0
- package/third-party/chromium-synchronization/inspector-issueAdded-types-test.js +2 -0
- package/third-party/chromium-synchronization/installability-errors-test.js +2 -0
- package/tsconfig.json +0 -1
- package/types/artifacts.d.ts +9 -48
- package/types/config.d.ts +0 -2
- package/types/externs.d.ts +2 -2
- package/types/gatherer.d.ts +2 -1
- package/types/global-lh.d.ts +0 -3
- package/types/lhr/audit-details.d.ts +3 -1
- package/types/lhr/lhr.d.ts +2 -2
- package/types/lhr/treemap.d.ts +1 -0
- package/lighthouse-core/audits/script-elements-test-audit.js +0 -30
- package/lighthouse-core/gather/gatherers/scripts.js +0 -154
- package/report/test/.eslintrc.cjs +0 -11
- 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://
|
|
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', '
|
|
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.
|
|
277
|
+
* @param {LH.GathererArtifacts['ScriptElements']} scripts
|
|
278
278
|
* @param {LH.Artifacts.NetworkRequest[]} networkRecords
|
|
279
279
|
* @param {LH.Artifacts.Bundle[]} bundles
|
|
280
|
-
* @return {Map<
|
|
280
|
+
* @return {Map<string, PatternMatchResult[]>}
|
|
281
281
|
*/
|
|
282
282
|
static detectAcrossScripts(matcher, scripts, networkRecords, bundles) {
|
|
283
|
-
/** @type {Map<
|
|
284
|
-
const
|
|
283
|
+
/** @type {Map<string, PatternMatchResult[]>} */
|
|
284
|
+
const urlToMatchResults = new Map();
|
|
285
285
|
const polyfillData = this.getPolyfillData();
|
|
286
286
|
|
|
287
|
-
for (const
|
|
288
|
-
if (!
|
|
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(
|
|
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.
|
|
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
|
-
|
|
316
|
+
urlToMatchResults.set(networkRecord.url, matches);
|
|
315
317
|
}
|
|
316
318
|
|
|
317
|
-
return
|
|
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.
|
|
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
|
|
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
|
|
413
|
-
this.detectAcrossScripts(matcher, artifacts.
|
|
414
|
-
for (const [
|
|
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,
|
|
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
|
|
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.
|
|
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(
|
|
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'
|
|
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
|
|
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
|
|
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 ||
|
|
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
|
|
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: ['
|
|
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.
|
|
83
|
-
|
|
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
|
-
|
|
88
|
-
|
|
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(
|
|
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
|
-
|
|
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', '
|
|
72
|
-
'devtoolsLogs', 'traces'
|
|
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 [
|
|
91
|
-
const
|
|
92
|
-
|
|
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({
|
|
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:
|
|
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'
|
|
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'
|
|
40
|
+
requiredArtifacts: ['ResponseCompression', 'GatherContext', 'devtoolsLogs', 'traces'],
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
|