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
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
const Audit = require('./audit.js');
|
|
9
9
|
const i18n = require('../lib/i18n/i18n.js');
|
|
10
10
|
const MainResource = require('../computed/main-resource.js');
|
|
11
|
+
const NetworkRecords = require('../computed/network-records.js');
|
|
12
|
+
const NetworkAnalyzer = require('../lib/dependency-graph/simulator/network-analyzer.js');
|
|
11
13
|
|
|
12
14
|
const UIStrings = {
|
|
13
15
|
/** Title of a diagnostic audit that provides detail on how long it took from starting a request to when the server started responding. This descriptive title is shown to users when the amount is acceptable and no user action is required. */
|
|
@@ -37,7 +39,7 @@ class ServerResponseTime extends Audit {
|
|
|
37
39
|
title: str_(UIStrings.title),
|
|
38
40
|
failureTitle: str_(UIStrings.failureTitle),
|
|
39
41
|
description: str_(UIStrings.description),
|
|
40
|
-
supportedModes: ['navigation'],
|
|
42
|
+
supportedModes: ['timespan', 'navigation'],
|
|
41
43
|
requiredArtifacts: ['devtoolsLogs', 'URL', 'GatherContext'],
|
|
42
44
|
};
|
|
43
45
|
}
|
|
@@ -59,7 +61,20 @@ class ServerResponseTime extends Audit {
|
|
|
59
61
|
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
|
|
60
62
|
|
|
61
63
|
/** @type {LH.Artifacts.NetworkRequest} */
|
|
62
|
-
|
|
64
|
+
let mainResource;
|
|
65
|
+
if (artifacts.GatherContext.gatherMode === 'timespan') {
|
|
66
|
+
const networkRecords = await NetworkRecords.request(devtoolsLog, context);
|
|
67
|
+
const optionalMainResource = NetworkAnalyzer.findOptionalMainDocument(
|
|
68
|
+
networkRecords,
|
|
69
|
+
artifacts.URL.finalUrl
|
|
70
|
+
);
|
|
71
|
+
if (!optionalMainResource) {
|
|
72
|
+
return {score: null, notApplicable: true};
|
|
73
|
+
}
|
|
74
|
+
mainResource = optionalMainResource;
|
|
75
|
+
} else {
|
|
76
|
+
mainResource = await MainResource.request({devtoolsLog, URL: artifacts.URL}, context);
|
|
77
|
+
}
|
|
63
78
|
|
|
64
79
|
const responseTime = ServerResponseTime.calculateResponseTime(mainResource);
|
|
65
80
|
const passed = responseTime < TOO_SLOW_THRESHOLD_MS;
|
|
@@ -51,7 +51,6 @@ class ServiceWorker extends Audit {
|
|
|
51
51
|
title: str_(UIStrings.title),
|
|
52
52
|
failureTitle: str_(UIStrings.failureTitle),
|
|
53
53
|
description: str_(UIStrings.description),
|
|
54
|
-
supportedModes: ['navigation'],
|
|
55
54
|
requiredArtifacts: ['URL', 'ServiceWorker', 'WebAppManifest'],
|
|
56
55
|
};
|
|
57
56
|
}
|
|
@@ -129,12 +128,8 @@ class ServiceWorker extends Audit {
|
|
|
129
128
|
* @return {LH.Audit.Product}
|
|
130
129
|
*/
|
|
131
130
|
static audit(artifacts) {
|
|
132
|
-
// Match against
|
|
133
|
-
|
|
134
|
-
// For this reason it is better to evaluate the SW in relation to the main document url rather than the final frame url.
|
|
135
|
-
const {mainDocumentUrl} = artifacts.URL;
|
|
136
|
-
if (!mainDocumentUrl) throw new Error('mainDocumentUrl must exist in navigation mode');
|
|
137
|
-
const pageUrl = new URL(mainDocumentUrl);
|
|
131
|
+
// Match against artifacts.URL.finalUrl so audit accounts for any redirects.
|
|
132
|
+
const pageUrl = new URL(artifacts.URL.finalUrl);
|
|
138
133
|
const {versions, registrations} = artifacts.ServiceWorker;
|
|
139
134
|
|
|
140
135
|
const versionsForOrigin = ServiceWorker.getVersionsForOrigin(versions, pageUrl);
|
|
@@ -140,9 +140,8 @@ class TimingBudget extends Audit {
|
|
|
140
140
|
const gatherContext = artifacts.GatherContext;
|
|
141
141
|
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
|
|
142
142
|
const trace = artifacts.traces[Audit.DEFAULT_PASS];
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const data = {trace, devtoolsLog, gatherContext, settings: context.settings, URL};
|
|
143
|
+
const mainResource = await MainResource.request({URL: artifacts.URL, devtoolsLog}, context);
|
|
144
|
+
const data = {trace, devtoolsLog, gatherContext, settings: context.settings};
|
|
146
145
|
const summary = (await TimingSummary.request(data, context)).metrics;
|
|
147
146
|
const budget = Budget.getMatchingBudget(context.settings.budgets, mainResource.url);
|
|
148
147
|
|
|
@@ -123,7 +123,7 @@ class UsesRelPreconnectAudit extends Audit {
|
|
|
123
123
|
MainResource.request({devtoolsLog, URL: artifacts.URL}, context),
|
|
124
124
|
LoadSimulator.request({devtoolsLog, settings}, context),
|
|
125
125
|
ProcessedNavigation.request(processedTrace, context),
|
|
126
|
-
PageDependencyGraph.request({trace, devtoolsLog
|
|
126
|
+
PageDependencyGraph.request({trace, devtoolsLog}, context),
|
|
127
127
|
]);
|
|
128
128
|
|
|
129
129
|
const {rtt, additionalRttByOrigin} = loadSimulator.getOptions();
|
|
@@ -217,7 +217,7 @@ class UsesRelPreloadAudit extends Audit {
|
|
|
217
217
|
|
|
218
218
|
const [mainResource, graph, simulator] = await Promise.all([
|
|
219
219
|
MainResource.request({devtoolsLog, URL}, context),
|
|
220
|
-
PageDependencyGraph.request({trace, devtoolsLog
|
|
220
|
+
PageDependencyGraph.request({trace, devtoolsLog}, context),
|
|
221
221
|
LoadSimulator.request(simulatorOptions, context),
|
|
222
222
|
]);
|
|
223
223
|
|
|
@@ -44,22 +44,22 @@ class ValidSourceMaps extends Audit {
|
|
|
44
44
|
title: str_(UIStrings.title),
|
|
45
45
|
failureTitle: str_(UIStrings.failureTitle),
|
|
46
46
|
description: str_(UIStrings.description),
|
|
47
|
-
requiredArtifacts: ['
|
|
47
|
+
requiredArtifacts: ['ScriptElements', 'SourceMaps', 'URL'],
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* Returns true if the size of the script exceeds a static threshold.
|
|
53
|
-
* @param {LH.Artifacts.
|
|
53
|
+
* @param {LH.Artifacts.ScriptElement} scriptElement
|
|
54
54
|
* @param {string} finalURL
|
|
55
55
|
* @return {boolean}
|
|
56
56
|
*/
|
|
57
|
-
static isLargeFirstPartyJS(
|
|
58
|
-
if (
|
|
57
|
+
static isLargeFirstPartyJS(scriptElement, finalURL) {
|
|
58
|
+
if (scriptElement.content === null) return false;
|
|
59
59
|
|
|
60
|
-
const isLargeJS =
|
|
61
|
-
const isFirstPartyJS =
|
|
62
|
-
thirdPartyWeb.isFirstParty(
|
|
60
|
+
const isLargeJS = scriptElement.content.length >= LARGE_JS_BYTE_THRESHOLD;
|
|
61
|
+
const isFirstPartyJS = scriptElement.src ?
|
|
62
|
+
thirdPartyWeb.isFirstParty(scriptElement.src, thirdPartyWeb.getEntity(finalURL)) : false;
|
|
63
63
|
|
|
64
64
|
return isLargeJS && isFirstPartyJS;
|
|
65
65
|
}
|
|
@@ -75,14 +75,16 @@ class ValidSourceMaps extends Audit {
|
|
|
75
75
|
|
|
76
76
|
let missingMapsForLargeFirstPartyFile = false;
|
|
77
77
|
const results = [];
|
|
78
|
-
for (const
|
|
79
|
-
|
|
78
|
+
for (const scriptElement of artifacts.ScriptElements) {
|
|
79
|
+
if (!scriptElement.src) continue; // TODO: inline scripts, how do they work?
|
|
80
|
+
|
|
81
|
+
const sourceMap = SourceMaps.find(m => m.scriptUrl === scriptElement.src);
|
|
80
82
|
const errors = [];
|
|
81
|
-
const isLargeFirstParty = this.isLargeFirstPartyJS(
|
|
83
|
+
const isLargeFirstParty = this.isLargeFirstPartyJS(scriptElement, artifacts.URL.finalUrl);
|
|
82
84
|
|
|
83
85
|
if (isLargeFirstParty && (!sourceMap || !sourceMap.map)) {
|
|
84
86
|
missingMapsForLargeFirstPartyFile = true;
|
|
85
|
-
isMissingMapForLargeFirstPartyScriptUrl.add(
|
|
87
|
+
isMissingMapForLargeFirstPartyScriptUrl.add(scriptElement.src);
|
|
86
88
|
errors.push({error: str_(UIStrings.missingSourceMapErrorMessage)});
|
|
87
89
|
}
|
|
88
90
|
|
|
@@ -105,7 +107,7 @@ class ValidSourceMaps extends Audit {
|
|
|
105
107
|
|
|
106
108
|
if (sourceMap || errors.length) {
|
|
107
109
|
results.push({
|
|
108
|
-
scriptUrl:
|
|
110
|
+
scriptUrl: scriptElement.src,
|
|
109
111
|
sourceMapUrl: sourceMap?.sourceMapUrl,
|
|
110
112
|
subItems: {
|
|
111
113
|
type: /** @type {const} */ ('subitems'),
|
|
@@ -31,7 +31,7 @@ class ViolationAudit extends Audit {
|
|
|
31
31
|
return artifacts.ConsoleMessages
|
|
32
32
|
.filter(entry => entry.url && entry.source === 'violation' && pattern.test(entry.text))
|
|
33
33
|
.map(entry => {
|
|
34
|
-
const bundle = bundles.find(bundle => bundle.script.
|
|
34
|
+
const bundle = bundles.find(bundle => bundle.script.src === entry.url);
|
|
35
35
|
return Audit.makeSourceLocationFromConsoleMessage(entry, bundle);
|
|
36
36
|
})
|
|
37
37
|
.filter(filterUndefined)
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright 2022 The Lighthouse Authors. All Rights Reserved.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
4
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const Audit = require('./audit.js');
|
|
9
|
+
const ComputedResponsivenes = require('../computed/metrics/responsiveness.js');
|
|
10
|
+
const ProcessedTrace = require('../computed/processed-trace.js');
|
|
11
|
+
const i18n = require('../lib/i18n/i18n.js');
|
|
12
|
+
const NetworkRecords = require('../computed/network-records.js');
|
|
13
|
+
const MainThreadTasks = require('../lib/tracehouse/main-thread-tasks.js');
|
|
14
|
+
const {taskGroups} = require('../lib/tracehouse/task-groups.js');
|
|
15
|
+
const TraceProcessor = require('../lib/tracehouse/trace-processor.js');
|
|
16
|
+
const {getExecutionTimingsByURL} = require('../lib/tracehouse/task-summary.js');
|
|
17
|
+
const inpThresholds = require('./metrics/experimental-interaction-to-next-paint.js').defaultOptions;
|
|
18
|
+
const LHError = require('../lib/lh-error.js');
|
|
19
|
+
|
|
20
|
+
/** @typedef {import('../computed/metrics/responsiveness.js').EventTimingEvent} EventTimingEvent */
|
|
21
|
+
/** @typedef {import('../lib/tracehouse/main-thread-tasks.js').TaskNode} TaskNode */
|
|
22
|
+
|
|
23
|
+
const TASK_THRESHOLD = 1;
|
|
24
|
+
|
|
25
|
+
const UIStrings = {
|
|
26
|
+
/** Title of a diagnostic audit that provides detail on the main thread work the browser did during a key user interaction. This descriptive title is shown to users when the amount is acceptable and no user action is required. */
|
|
27
|
+
title: 'Minimizes work during key interaction',
|
|
28
|
+
/** Title of a diagnostic audit that provides detail on the main thread work the browser did during a key user interaction. This imperative title is shown to users when there is a significant amount of execution time that could be reduced. */
|
|
29
|
+
failureTitle: 'Minimize work during key interaction',
|
|
30
|
+
/** Description of the work-during-interaction metric. This description is displayed within a tooltip when the user hovers on the metric name to see more. No character length limits. 'Learn More' becomes link text to additional documentation. */
|
|
31
|
+
description: 'This is the thread-blocking work occurring during the Interaction to Next Paint measurement. [Learn more](https://web.dev/inp/).',
|
|
32
|
+
/** Label for a column in a data table; entries will be information on the time that the browser is delayed before responding to user input. Ideally fits within a ~40 character limit. */
|
|
33
|
+
inputDelay: 'Input delay',
|
|
34
|
+
/** Label for a column in a data table; entries will be information on the time taken by code processing user input that delays a response to the user. Ideally fits within a ~40 character limit. */
|
|
35
|
+
processingDelay: 'Processing delay',
|
|
36
|
+
/** Label for a column in a data table; entries will be information on the time that the browser is delayed before presenting a response to user input on screen. Ideally fits within a ~40 character limit. */
|
|
37
|
+
presentationDelay: 'Presentation delay',
|
|
38
|
+
/**
|
|
39
|
+
* @description Summary text that identifies the time the browser took to process a user interaction.
|
|
40
|
+
* @example {mousedown} interactionType
|
|
41
|
+
*/
|
|
42
|
+
displayValue: `{timeInMs, number, milliseconds}\xa0ms spent on event '{interactionType}'`,
|
|
43
|
+
/** Label for a column in a data table; entries will the UI element that was the target of a user interaction (for example, a button that was clicked on). Ideally fits within a ~40 character limit. */
|
|
44
|
+
eventTarget: 'Event target',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @fileoverview This metric gives a high-percentile measure of responsiveness to input.
|
|
51
|
+
*/
|
|
52
|
+
class WorkDuringInteraction extends Audit {
|
|
53
|
+
/**
|
|
54
|
+
* @return {LH.Audit.Meta}
|
|
55
|
+
*/
|
|
56
|
+
static get meta() {
|
|
57
|
+
return {
|
|
58
|
+
id: 'work-during-interaction',
|
|
59
|
+
title: str_(UIStrings.title),
|
|
60
|
+
failureTitle: str_(UIStrings.failureTitle),
|
|
61
|
+
description: str_(UIStrings.description),
|
|
62
|
+
scoreDisplayMode: Audit.SCORING_MODES.NUMERIC,
|
|
63
|
+
supportedModes: ['timespan'],
|
|
64
|
+
requiredArtifacts: ['traces', 'devtoolsLogs', 'TraceElements'],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {TaskNode} task
|
|
70
|
+
* @param {TaskNode|undefined} parent
|
|
71
|
+
* @param {number} startTs
|
|
72
|
+
* @param {number} endTs
|
|
73
|
+
* @return {number}
|
|
74
|
+
*/
|
|
75
|
+
static recursivelyClipTasks(task, parent, startTs, endTs) {
|
|
76
|
+
const taskEventStart = task.event.ts;
|
|
77
|
+
const taskEventEnd = task.endEvent?.ts ?? task.event.ts + Number(task.event.dur || 0);
|
|
78
|
+
|
|
79
|
+
task.startTime = Math.max(startTs, Math.min(endTs, taskEventStart)) / 1000;
|
|
80
|
+
task.endTime = Math.max(startTs, Math.min(endTs, taskEventEnd)) / 1000;
|
|
81
|
+
task.duration = task.endTime - task.startTime;
|
|
82
|
+
|
|
83
|
+
const childTime = task.children
|
|
84
|
+
.map(child => WorkDuringInteraction.recursivelyClipTasks(child, task, startTs, endTs))
|
|
85
|
+
.reduce((sum, child) => sum + child, 0);
|
|
86
|
+
task.selfTime = task.duration - childTime;
|
|
87
|
+
return task.duration;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Clip the tasks by the start and end points. Take the easy route and drop
|
|
92
|
+
* to duration 0 if out of bounds, since only durations are needed in the
|
|
93
|
+
* end (for now).
|
|
94
|
+
* Assumes owned tasks, so modifies in place. Can be called multiple times on
|
|
95
|
+
* the same `tasks` because always computed from original event timing.
|
|
96
|
+
* @param {Array<TaskNode>} tasks
|
|
97
|
+
* @param {number} startTs
|
|
98
|
+
* @param {number} endTs
|
|
99
|
+
*/
|
|
100
|
+
static clipTasksByTs(tasks, startTs, endTs) {
|
|
101
|
+
for (const task of tasks) {
|
|
102
|
+
if (task.parent) continue;
|
|
103
|
+
WorkDuringInteraction.recursivelyClipTasks(task, undefined, startTs, endTs);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {EventTimingEvent} interactionEvent
|
|
109
|
+
*/
|
|
110
|
+
static getPhaseTimes(interactionEvent) {
|
|
111
|
+
const interactionData = interactionEvent.args.data;
|
|
112
|
+
const startTs = interactionEvent.ts;
|
|
113
|
+
const navStart = startTs - interactionData.timeStamp * 1000;
|
|
114
|
+
const processingStartTs = navStart + interactionData.processingStart * 1000;
|
|
115
|
+
const processingEndTs = navStart + interactionData.processingEnd * 1000;
|
|
116
|
+
const endTs = startTs + interactionData.duration * 1000;
|
|
117
|
+
return {
|
|
118
|
+
inputDelay: {startTs, endTs: processingStartTs},
|
|
119
|
+
processingDelay: {startTs: processingStartTs, endTs: processingEndTs},
|
|
120
|
+
presentationDelay: {startTs: processingEndTs, endTs},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @param {EventTimingEvent} interactionEvent
|
|
126
|
+
* @param {LH.Trace} trace
|
|
127
|
+
* @param {LH.Artifacts.ProcessedTrace} processedTrace
|
|
128
|
+
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
|
|
129
|
+
* @return {{table: LH.Audit.Details.Table, phases: Record<string, {startTs: number, endTs: number}>}}
|
|
130
|
+
*/
|
|
131
|
+
static getThreadBreakdownTable(interactionEvent, trace, processedTrace, networkRecords) {
|
|
132
|
+
// Limit to interactionEvent's thread.
|
|
133
|
+
// TODO(bckenny): limit to interactionEvent's navigation.
|
|
134
|
+
const threadEvents = TraceProcessor.filteredTraceSort(trace.traceEvents, evt => {
|
|
135
|
+
return evt.pid === interactionEvent.pid && evt.tid === interactionEvent.tid;
|
|
136
|
+
});
|
|
137
|
+
const traceEndTs = threadEvents.reduce((endTs, evt) => {
|
|
138
|
+
return Math.max(evt.ts + (evt.dur || 0), endTs);
|
|
139
|
+
}, 0);
|
|
140
|
+
// frames is only used for URL attribution, so can include all frames, even if OOPIF.
|
|
141
|
+
const {frames} = processedTrace;
|
|
142
|
+
const threadTasks = MainThreadTasks.getMainThreadTasks(threadEvents, frames, traceEndTs);
|
|
143
|
+
|
|
144
|
+
const phases = WorkDuringInteraction.getPhaseTimes(interactionEvent);
|
|
145
|
+
|
|
146
|
+
/** @type {LH.Audit.Details.TableItem[]} */
|
|
147
|
+
const items = [];
|
|
148
|
+
for (const [phaseName, phaseTimes] of Object.entries(phases)) {
|
|
149
|
+
// Clip tasks to start and end time.
|
|
150
|
+
WorkDuringInteraction.clipTasksByTs(threadTasks, phaseTimes.startTs, phaseTimes.endTs);
|
|
151
|
+
const executionTimings = getExecutionTimingsByURL(threadTasks, networkRecords);
|
|
152
|
+
|
|
153
|
+
const results = [];
|
|
154
|
+
for (const [url, timingByGroupId] of executionTimings) {
|
|
155
|
+
const totalExecutionTimeForURL = Object.values(timingByGroupId)
|
|
156
|
+
.reduce((total, timespanMs) => total + timespanMs);
|
|
157
|
+
|
|
158
|
+
const scriptingTotal = timingByGroupId[taskGroups.scriptEvaluation.id] || 0;
|
|
159
|
+
const layoutTotal = timingByGroupId[taskGroups.styleLayout.id] || 0;
|
|
160
|
+
const renderTotal = timingByGroupId[taskGroups.paintCompositeRender.id] || 0;
|
|
161
|
+
|
|
162
|
+
results.push({
|
|
163
|
+
url: url,
|
|
164
|
+
total: totalExecutionTimeForURL,
|
|
165
|
+
scripting: scriptingTotal,
|
|
166
|
+
layout: layoutTotal,
|
|
167
|
+
render: renderTotal,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const filteredResults = results
|
|
172
|
+
.filter(result => result.total > TASK_THRESHOLD)
|
|
173
|
+
.sort((a, b) => b.total - a.total);
|
|
174
|
+
|
|
175
|
+
items.push({
|
|
176
|
+
phase: str_(UIStrings[/** @type {keyof UIStrings} */ (phaseName)]),
|
|
177
|
+
total: (phaseTimes.endTs - phaseTimes.startTs) / 1000,
|
|
178
|
+
subItems: {
|
|
179
|
+
type: 'subitems',
|
|
180
|
+
items: filteredResults,
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** @type {LH.Audit.Details.Table['headings']} */
|
|
186
|
+
const headings = [
|
|
187
|
+
/* eslint-disable max-len */
|
|
188
|
+
{key: 'phase', itemType: 'text', subItemsHeading: {key: 'url', itemType: 'url'}, text: 'Phase'},
|
|
189
|
+
{key: 'total', itemType: 'ms', subItemsHeading: {key: 'total', granularity: 1, itemType: 'ms'}, granularity: 1, text: 'Total time'},
|
|
190
|
+
{key: null, itemType: 'ms', subItemsHeading: {key: 'scripting', granularity: 1, itemType: 'ms'}, text: 'Script evaluation'},
|
|
191
|
+
{key: null, itemType: 'ms', subItemsHeading: {key: 'layout', granularity: 1, itemType: 'ms'}, text: taskGroups.styleLayout.label},
|
|
192
|
+
{key: null, itemType: 'ms', subItemsHeading: {key: 'render', granularity: 1, itemType: 'ms'}, text: taskGroups.paintCompositeRender.label},
|
|
193
|
+
/* eslint-enable max-len */
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
table: Audit.makeTableDetails(headings, items),
|
|
198
|
+
phases,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @param {LH.Artifacts['TraceElements']} traceElements
|
|
204
|
+
* @return {LH.Audit.Details.Table | undefined}
|
|
205
|
+
*/
|
|
206
|
+
static getTraceElementTable(traceElements) {
|
|
207
|
+
const responsivenessElement = traceElements.find(el => el.traceEventType === 'responsiveness');
|
|
208
|
+
if (!responsivenessElement) return;
|
|
209
|
+
|
|
210
|
+
/** @type {LH.Audit.Details.Table['headings']} */
|
|
211
|
+
const headings = [
|
|
212
|
+
{key: 'node', itemType: 'node', text: str_(UIStrings.eventTarget)},
|
|
213
|
+
];
|
|
214
|
+
const elementItems = [{node: Audit.makeNodeItem(responsivenessElement.node)}];
|
|
215
|
+
|
|
216
|
+
return Audit.makeTableDetails(headings, elementItems);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @param {LH.Artifacts} artifacts
|
|
221
|
+
* @param {LH.Audit.Context} context
|
|
222
|
+
* @return {Promise<LH.Audit.Product>}
|
|
223
|
+
*/
|
|
224
|
+
static async audit(artifacts, context) {
|
|
225
|
+
const {settings} = context;
|
|
226
|
+
// TODO: responsiveness isn't yet supported by lantern.
|
|
227
|
+
if (settings.throttlingMethod === 'simulate') {
|
|
228
|
+
return {score: null, notApplicable: true};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const trace = artifacts.traces[WorkDuringInteraction.DEFAULT_PASS];
|
|
232
|
+
const metricData = {trace, settings};
|
|
233
|
+
const interactionEvent = await ComputedResponsivenes.request(metricData, context);
|
|
234
|
+
// If no interaction, diagnostic audit is n/a.
|
|
235
|
+
if (interactionEvent === null) {
|
|
236
|
+
return {score: null, notApplicable: true};
|
|
237
|
+
}
|
|
238
|
+
// TODO: remove workaround once 103.0.5052.0 is sufficiently released.
|
|
239
|
+
if (interactionEvent.name === 'FallbackTiming') {
|
|
240
|
+
throw new LHError(
|
|
241
|
+
LHError.errors.UNSUPPORTED_OLD_CHROME,
|
|
242
|
+
{featureName: 'detailed EventTiming trace events'}
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const auditDetailsItems = [];
|
|
247
|
+
|
|
248
|
+
const traceElementItem = WorkDuringInteraction.getTraceElementTable(artifacts.TraceElements);
|
|
249
|
+
if (traceElementItem) auditDetailsItems.push(traceElementItem);
|
|
250
|
+
|
|
251
|
+
const devtoolsLog = artifacts.devtoolsLogs[WorkDuringInteraction.DEFAULT_PASS];
|
|
252
|
+
// Network records will usually be empty for timespans.
|
|
253
|
+
const networkRecords = await NetworkRecords.request(devtoolsLog, context);
|
|
254
|
+
const processedTrace = await ProcessedTrace.request(trace, context);
|
|
255
|
+
const {table: breakdownTable, phases} = WorkDuringInteraction.getThreadBreakdownTable(
|
|
256
|
+
interactionEvent, trace, processedTrace, networkRecords);
|
|
257
|
+
auditDetailsItems.push(breakdownTable);
|
|
258
|
+
|
|
259
|
+
const interactionType = interactionEvent.args.data.type;
|
|
260
|
+
auditDetailsItems.push({
|
|
261
|
+
type: /** @type {const} */ ('debugdata'),
|
|
262
|
+
interactionType,
|
|
263
|
+
phases,
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
const duration = interactionEvent.args.data.duration;
|
|
267
|
+
const displayValue = str_(UIStrings.displayValue, {timeInMs: duration, interactionType});
|
|
268
|
+
return {
|
|
269
|
+
score: duration < inpThresholds.p10 ? 1 : 0,
|
|
270
|
+
displayValue,
|
|
271
|
+
details: {
|
|
272
|
+
type: 'list',
|
|
273
|
+
items: auditDetailsItems,
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
module.exports = WorkDuringInteraction;
|
|
280
|
+
module.exports.UIStrings = UIStrings;
|
|
@@ -117,9 +117,6 @@ class CriticalRequestChains {
|
|
|
117
117
|
// Ignore if some ancestor is not a critical request.
|
|
118
118
|
if (networkPath.some(r => !CriticalRequestChains.isCritical(r, mainResource))) return;
|
|
119
119
|
|
|
120
|
-
// Ignore non-network things (like data urls).
|
|
121
|
-
if (NetworkRequest.isNonNetworkRequest(node.record)) return;
|
|
122
|
-
|
|
123
120
|
addChain(networkPath);
|
|
124
121
|
}, getNextNodes);
|
|
125
122
|
|
|
@@ -132,8 +129,15 @@ class CriticalRequestChains {
|
|
|
132
129
|
* @return {Promise<LH.Artifacts.CriticalRequestNode>}
|
|
133
130
|
*/
|
|
134
131
|
static async compute_(data, context) {
|
|
135
|
-
const mainResource = await MainResource.request(
|
|
136
|
-
|
|
132
|
+
const mainResource = await MainResource.request({
|
|
133
|
+
URL: data.URL,
|
|
134
|
+
devtoolsLog: data.devtoolsLog,
|
|
135
|
+
}, context);
|
|
136
|
+
|
|
137
|
+
const graph = await PageDependencyGraph.request({
|
|
138
|
+
trace: data.trace,
|
|
139
|
+
devtoolsLog: data.devtoolsLog,
|
|
140
|
+
}, context);
|
|
137
141
|
|
|
138
142
|
return CriticalRequestChains.extractChainsFromGraph(mainResource, graph);
|
|
139
143
|
}
|
|
@@ -12,15 +12,14 @@ const SDK = require('../lib/cdt/SDK.js');
|
|
|
12
12
|
/**
|
|
13
13
|
* Calculate the number of bytes contributed by each source file
|
|
14
14
|
* @param {LH.Artifacts.Bundle['map']} map
|
|
15
|
-
* @param {number} contentLength
|
|
16
15
|
* @param {string} content
|
|
17
16
|
* @return {LH.Artifacts.Bundle['sizes']}
|
|
18
17
|
*/
|
|
19
|
-
function computeGeneratedFileSizes(map,
|
|
18
|
+
function computeGeneratedFileSizes(map, content) {
|
|
20
19
|
const lines = content.split('\n');
|
|
21
20
|
/** @type {Record<string, number>} */
|
|
22
21
|
const files = {};
|
|
23
|
-
const totalBytes =
|
|
22
|
+
const totalBytes = content.length;
|
|
24
23
|
let unmappedBytes = totalBytes;
|
|
25
24
|
|
|
26
25
|
// @ts-expect-error: This function is added in SDK.js. This will eventually be added to CDT.
|
|
@@ -79,10 +78,10 @@ function computeGeneratedFileSizes(map, contentLength, content) {
|
|
|
79
78
|
|
|
80
79
|
class JSBundles {
|
|
81
80
|
/**
|
|
82
|
-
* @param {Pick<LH.Artifacts, 'SourceMaps'|'
|
|
81
|
+
* @param {Pick<LH.Artifacts, 'SourceMaps'|'ScriptElements'>} artifacts
|
|
83
82
|
*/
|
|
84
83
|
static async compute_(artifacts) {
|
|
85
|
-
const {SourceMaps,
|
|
84
|
+
const {SourceMaps, ScriptElements} = artifacts;
|
|
86
85
|
|
|
87
86
|
/** @type {LH.Artifacts.Bundle[]} */
|
|
88
87
|
const bundles = [];
|
|
@@ -90,22 +89,23 @@ class JSBundles {
|
|
|
90
89
|
// Collate map and script, compute file sizes.
|
|
91
90
|
for (const SourceMap of SourceMaps) {
|
|
92
91
|
if (!SourceMap.map) continue;
|
|
93
|
-
const {
|
|
92
|
+
const {scriptUrl, map: rawMap} = SourceMap;
|
|
94
93
|
|
|
95
94
|
if (!rawMap.mappings) continue;
|
|
96
95
|
|
|
97
|
-
const
|
|
98
|
-
if (!
|
|
96
|
+
const scriptElement = ScriptElements.find(s => s.src === scriptUrl);
|
|
97
|
+
if (!scriptElement) continue;
|
|
99
98
|
|
|
100
99
|
const compiledUrl = SourceMap.scriptUrl || 'compiled.js';
|
|
101
100
|
const mapUrl = SourceMap.sourceMapUrl || 'compiled.js.map';
|
|
102
101
|
const map = new SDK.TextSourceMap(compiledUrl, mapUrl, rawMap);
|
|
103
102
|
|
|
104
|
-
const
|
|
103
|
+
const content = scriptElement?.content ? scriptElement.content : '';
|
|
104
|
+
const sizes = computeGeneratedFileSizes(map, content);
|
|
105
105
|
|
|
106
106
|
const bundle = {
|
|
107
107
|
rawMap,
|
|
108
|
-
script,
|
|
108
|
+
script: scriptElement,
|
|
109
109
|
map,
|
|
110
110
|
sizes,
|
|
111
111
|
};
|
|
@@ -116,4 +116,4 @@ class JSBundles {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
module.exports = makeComputedArtifact(JSBundles, ['
|
|
119
|
+
module.exports = makeComputedArtifact(JSBundles, ['ScriptElements', 'SourceMaps']);
|
|
@@ -20,10 +20,9 @@ class MainResource {
|
|
|
20
20
|
* @return {Promise<LH.Artifacts.NetworkRequest>}
|
|
21
21
|
*/
|
|
22
22
|
static async compute_(data, context) {
|
|
23
|
-
const
|
|
24
|
-
if (!mainDocumentUrl) throw new Error('mainDocumentUrl must exist to get the main resource');
|
|
23
|
+
const finalUrl = data.URL.finalUrl;
|
|
25
24
|
const requests = await NetworkRecords.request(data.devtoolsLog, context);
|
|
26
|
-
const mainResource = NetworkAnalyzer.
|
|
25
|
+
const mainResource = NetworkAnalyzer.findMainDocument(requests, finalUrl);
|
|
27
26
|
if (!mainResource) {
|
|
28
27
|
throw new Error('Unable to identify the main resource');
|
|
29
28
|
}
|
|
@@ -33,5 +33,5 @@ class FirstContentfulPaintAllFrames extends NavigationMetric {
|
|
|
33
33
|
|
|
34
34
|
module.exports = makeComputedArtifact(
|
|
35
35
|
FirstContentfulPaintAllFrames,
|
|
36
|
-
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace'
|
|
36
|
+
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace']
|
|
37
37
|
);
|
|
@@ -36,5 +36,5 @@ class FirstContentfulPaint extends NavigationMetric {
|
|
|
36
36
|
|
|
37
37
|
module.exports = makeComputedArtifact(
|
|
38
38
|
FirstContentfulPaint,
|
|
39
|
-
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace'
|
|
39
|
+
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace']
|
|
40
40
|
);
|
|
@@ -40,5 +40,5 @@ class FirstMeaningfulPaint extends NavigationMetric {
|
|
|
40
40
|
|
|
41
41
|
module.exports = makeComputedArtifact(
|
|
42
42
|
FirstMeaningfulPaint,
|
|
43
|
-
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace'
|
|
43
|
+
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace']
|
|
44
44
|
);
|
|
@@ -183,7 +183,7 @@ class Interactive extends NavigationMetric {
|
|
|
183
183
|
|
|
184
184
|
module.exports = makeComputedArtifact(
|
|
185
185
|
Interactive,
|
|
186
|
-
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace'
|
|
186
|
+
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace']
|
|
187
187
|
);
|
|
188
188
|
|
|
189
189
|
/**
|
|
@@ -200,5 +200,5 @@ class LanternFirstContentfulPaint extends LanternMetric {
|
|
|
200
200
|
|
|
201
201
|
module.exports = makeComputedArtifact(
|
|
202
202
|
LanternFirstContentfulPaint,
|
|
203
|
-
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace'
|
|
203
|
+
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace']
|
|
204
204
|
);
|
|
@@ -79,5 +79,5 @@ class LanternFirstMeaningfulPaint extends LanternMetric {
|
|
|
79
79
|
|
|
80
80
|
module.exports = makeComputedArtifact(
|
|
81
81
|
LanternFirstMeaningfulPaint,
|
|
82
|
-
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace'
|
|
82
|
+
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace']
|
|
83
83
|
);
|
|
@@ -109,5 +109,5 @@ class LanternInteractive extends LanternMetric {
|
|
|
109
109
|
|
|
110
110
|
module.exports = makeComputedArtifact(
|
|
111
111
|
LanternInteractive,
|
|
112
|
-
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace'
|
|
112
|
+
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace']
|
|
113
113
|
);
|
|
@@ -107,5 +107,5 @@ class LanternLargestContentfulPaint extends LanternMetric {
|
|
|
107
107
|
|
|
108
108
|
module.exports = makeComputedArtifact(
|
|
109
109
|
LanternLargestContentfulPaint,
|
|
110
|
-
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace'
|
|
110
|
+
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace']
|
|
111
111
|
);
|
|
@@ -89,5 +89,5 @@ class LanternMaxPotentialFID extends LanternMetricArtifact {
|
|
|
89
89
|
|
|
90
90
|
module.exports = makeComputedArtifact(
|
|
91
91
|
LanternMaxPotentialFID,
|
|
92
|
-
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace'
|
|
92
|
+
['devtoolsLog', 'gatherContext', 'settings', 'simulator', 'trace']
|
|
93
93
|
);
|
|
@@ -101,15 +101,17 @@ class LanternMetricArtifact {
|
|
|
101
101
|
static async computeMetricWithGraphs(data, context, extras) {
|
|
102
102
|
// TODO: remove this fallback when lighthouse-pub-ads plugin can update.
|
|
103
103
|
const gatherContext = data.gatherContext || {gatherMode: 'navigation'};
|
|
104
|
+
const {trace, devtoolsLog, settings} = data;
|
|
104
105
|
if (gatherContext.gatherMode !== 'navigation') {
|
|
105
106
|
throw new Error(`Lantern metrics can only be computed on navigations`);
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
const metricName = this.name.replace('Lantern', '');
|
|
109
|
-
const graph = await PageDependencyGraph.request(
|
|
110
|
-
const processedTrace = await ProcessedTrace.request(
|
|
110
|
+
const graph = await PageDependencyGraph.request({trace, devtoolsLog}, context);
|
|
111
|
+
const processedTrace = await ProcessedTrace.request(trace, context);
|
|
111
112
|
const processedNavigation = await ProcessedNavigation.request(processedTrace, context);
|
|
112
|
-
const simulator = data.simulator ||
|
|
113
|
+
const simulator = data.simulator ||
|
|
114
|
+
(await LoadSimulator.request({devtoolsLog, settings}, context));
|
|
113
115
|
|
|
114
116
|
const optimisticGraph = this.getOptimisticGraph(graph, processedNavigation);
|
|
115
117
|
const pessimisticGraph = this.getPessimisticGraph(graph, processedNavigation);
|