diff --git a/lighthouse-core/audits/byte-efficiency/duplicated-javascript.js b/lighthouse-core/audits/byte-efficiency/duplicated-javascript.js index 278e581aa4ee..1c912440d00e 100644 --- a/lighthouse-core/audits/byte-efficiency/duplicated-javascript.js +++ b/lighthouse-core/audits/byte-efficiency/duplicated-javascript.js @@ -163,14 +163,13 @@ class DuplicatedJavascript extends ByteEfficiencyAudit { /** @type {number|undefined} */ let transferRatio = transferRatioByUrl.get(url); if (transferRatio === undefined) { - const networkRecord = getRequestForScript(networkRecords, script); - if (!script || script.length === undefined) { // This should never happen because we found the wasted bytes from bundles, which required contents in a ScriptElement. continue; } const contentLength = script.length; + const networkRecord = getRequestForScript(networkRecords, script); transferRatio = DuplicatedJavascript._estimateTransferRatio(networkRecord, contentLength); transferRatioByUrl.set(url, transferRatio); } diff --git a/lighthouse-core/audits/byte-efficiency/legacy-javascript.js b/lighthouse-core/audits/byte-efficiency/legacy-javascript.js index 907c1e976926..d6af4bb181e1 100644 --- a/lighthouse-core/audits/byte-efficiency/legacy-javascript.js +++ b/lighthouse-core/audits/byte-efficiency/legacy-javascript.js @@ -373,12 +373,12 @@ class LegacyJavascript extends ByteEfficiencyAudit { if (transferRatio !== undefined) return transferRatio; const script = artifacts.Scripts.find(script => script.url === url); - const networkRecord = getRequestForScript(networkRecords, script); if (!script || script.content === null) { // Can't find content, so just use 1. transferRatio = 1; } else { + const networkRecord = getRequestForScript(networkRecords, script); const contentLength = script.length || 0; const transferSize = ByteEfficiencyAudit.estimateTransferSize(networkRecord, contentLength, 'Script'); diff --git a/lighthouse-core/audits/diagnostics.js b/lighthouse-core/audits/diagnostics.js index f77ec7b21303..5928e57b9898 100644 --- a/lighthouse-core/audits/diagnostics.js +++ b/lighthouse-core/audits/diagnostics.js @@ -9,7 +9,7 @@ const Audit = require('./audit.js'); const MainThreadTasksComputed = require('../computed/main-thread-tasks.js'); const NetworkRecordsComputed = require('../computed/network-records.js'); const NetworkAnalysisComputed = require('../computed/network-analysis.js'); -const NetworkAnalyzer = require('../lib/dependency-graph/simulator/network-analyzer.js'); +const MainResource = require('../computed/main-resource.js'); class Diagnostics extends Audit { /** @@ -22,7 +22,7 @@ class Diagnostics extends Audit { title: 'Diagnostics', description: 'Collection of useful page vitals.', supportedModes: ['navigation'], - requiredArtifacts: ['traces', 'devtoolsLogs'], + requiredArtifacts: ['URL', 'traces', 'devtoolsLogs'], }; } @@ -37,9 +37,10 @@ class Diagnostics extends Audit { const tasks = await MainThreadTasksComputed.request(trace, context); const records = await NetworkRecordsComputed.request(devtoolsLog, context); const analysis = await NetworkAnalysisComputed.request(devtoolsLog, context); + const mainResource = await MainResource.request({devtoolsLog, URL: artifacts.URL}, context); const toplevelTasks = tasks.filter(t => !t.parent); - const mainDocumentTransferSize = NetworkAnalyzer.findMainDocument(records).transferSize; + const mainDocumentTransferSize = mainResource.transferSize; const totalByteWeight = records.reduce((sum, r) => sum + (r.transferSize || 0), 0); const totalTaskTime = toplevelTasks.reduce((sum, t) => sum + (t.duration || 0), 0); const maxRtt = Math.max(...analysis.additionalRttByOrigin.values()) + analysis.rtt; diff --git a/lighthouse-core/audits/seo/http-status-code.js b/lighthouse-core/audits/seo/http-status-code.js index e0a712db1098..9814b2bc72a1 100644 --- a/lighthouse-core/audits/seo/http-status-code.js +++ b/lighthouse-core/audits/seo/http-status-code.js @@ -6,11 +6,10 @@ 'use strict'; const Audit = require('../audit.js'); -const NetworkRecords = require('../../computed/network-records.js'); const HTTP_UNSUCCESSFUL_CODE_LOW = 400; const HTTP_UNSUCCESSFUL_CODE_HIGH = 599; const i18n = require('../../lib/i18n/i18n.js'); -const NetworkAnalyzer = require('../../lib/dependency-graph/simulator/network-analyzer.js'); +const MainResource = require('../../computed/main-resource.js'); const UIStrings = { /** Title of a Lighthouse audit that provides detail on the HTTP status code a page responds with. This descriptive title is shown when the page has responded with a valid HTTP status code. */ @@ -47,8 +46,7 @@ class HTTPStatusCode extends Audit { static async audit(artifacts, context) { const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS]; const URL = artifacts.URL; - const networkRecords = await NetworkRecords.request(devtoolsLog, context); - const mainResource = NetworkAnalyzer.findMainDocument(networkRecords, URL.finalUrl); + const mainResource = await MainResource.request({devtoolsLog, URL}, context); const statusCode = mainResource.statusCode; diff --git a/lighthouse-core/audits/server-response-time.js b/lighthouse-core/audits/server-response-time.js index 6f77f3e785fb..95838d28e2b3 100644 --- a/lighthouse-core/audits/server-response-time.js +++ b/lighthouse-core/audits/server-response-time.js @@ -8,8 +8,6 @@ const Audit = require('./audit.js'); const i18n = require('../lib/i18n/i18n.js'); const MainResource = require('../computed/main-resource.js'); -const NetworkRecords = require('../computed/network-records.js'); -const NetworkAnalyzer = require('../lib/dependency-graph/simulator/network-analyzer.js'); const UIStrings = { /** 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. */ @@ -39,7 +37,7 @@ class ServerResponseTime extends Audit { title: str_(UIStrings.title), failureTitle: str_(UIStrings.failureTitle), description: str_(UIStrings.description), - supportedModes: ['timespan', 'navigation'], + supportedModes: ['navigation'], requiredArtifacts: ['devtoolsLogs', 'URL', 'GatherContext'], }; } @@ -61,20 +59,7 @@ class ServerResponseTime extends Audit { const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS]; /** @type {LH.Artifacts.NetworkRequest} */ - let mainResource; - if (artifacts.GatherContext.gatherMode === 'timespan') { - const networkRecords = await NetworkRecords.request(devtoolsLog, context); - const optionalMainResource = NetworkAnalyzer.findOptionalMainDocument( - networkRecords, - artifacts.URL.finalUrl - ); - if (!optionalMainResource) { - return {score: null, notApplicable: true}; - } - mainResource = optionalMainResource; - } else { - mainResource = await MainResource.request({devtoolsLog, URL: artifacts.URL}, context); - } + const mainResource = await MainResource.request({devtoolsLog, URL: artifacts.URL}, context); const responseTime = ServerResponseTime.calculateResponseTime(mainResource); const passed = responseTime < TOO_SLOW_THRESHOLD_MS; diff --git a/lighthouse-core/computed/page-dependency-graph.js b/lighthouse-core/computed/page-dependency-graph.js index 833cb0451e89..4d861cfb393a 100644 --- a/lighthouse-core/computed/page-dependency-graph.js +++ b/lighthouse-core/computed/page-dependency-graph.js @@ -394,6 +394,9 @@ class PageDependencyGraph { const networkNodeOutput = PageDependencyGraph.getNetworkNodeOutput(networkRecords); const cpuNodes = PageDependencyGraph.getCPUNodes(processedTrace); + // TODO: Remove this usage of `findMainDocument` and create a new function to get the first document request. + // https://github.com/GoogleChrome/lighthouse/issues/8984 + // // The main document request is the earliest network request *of type document*. // This will be different from the root request when there are server redirects. const mainDocumentRequest = NetworkAnalyzer.findMainDocument(networkRecords); diff --git a/lighthouse-core/fraggle-rock/gather/navigation-runner.js b/lighthouse-core/fraggle-rock/gather/navigation-runner.js index 82520387b961..d37f17461d64 100644 --- a/lighthouse-core/fraggle-rock/gather/navigation-runner.js +++ b/lighthouse-core/fraggle-rock/gather/navigation-runner.js @@ -224,6 +224,7 @@ async function _navigation(navigationContext) { await collectPhaseArtifacts({phase: 'startInstrumentation', ...phaseState}); await collectPhaseArtifacts({phase: 'startSensitiveInstrumentation', ...phaseState}); const navigateResult = await _navigate(navigationContext); + phaseState.baseArtifacts.URL.finalUrl = navigateResult.finalUrl; phaseState.url = navigateResult.finalUrl; await collectPhaseArtifacts({phase: 'stopSensitiveInstrumentation', ...phaseState}); await collectPhaseArtifacts({phase: 'stopInstrumentation', ...phaseState}); diff --git a/lighthouse-core/gather/gather-runner.js b/lighthouse-core/gather/gather-runner.js index 35bf56808eaf..6519596254f2 100644 --- a/lighthouse-core/gather/gather-runner.js +++ b/lighthouse-core/gather/gather-runner.js @@ -80,6 +80,7 @@ class GatherRunner { ...passContext.passConfig, }); passContext.url = finalUrl; + passContext.baseArtifacts.URL.finalUrl = finalUrl; if (passContext.passConfig.loadFailureMode === 'fatal') { passContext.LighthouseRunWarnings.push(...warnings); } diff --git a/lighthouse-core/gather/gatherers/link-elements.js b/lighthouse-core/gather/gatherers/link-elements.js index a2561adaefcd..244bbd3f4174 100644 --- a/lighthouse-core/gather/gatherers/link-elements.js +++ b/lighthouse-core/gather/gatherers/link-elements.js @@ -8,10 +8,9 @@ const LinkHeader = require('http-link-header'); const FRGatherer = require('../../fraggle-rock/gather/base-gatherer.js'); const {URL} = require('../../lib/url-shim.js'); -const NetworkRecords = require('../../computed/network-records.js'); -const NetworkAnalyzer = require('../../lib/dependency-graph/simulator/network-analyzer.js'); const pageFunctions = require('../../lib/page-functions.js'); const DevtoolsLog = require('./devtools-log.js'); +const MainResource = require('../../computed/main-resource.js'); /* globals HTMLLinkElement getNodeDetails */ @@ -114,12 +113,12 @@ class LinkElements extends FRGatherer { /** * @param {LH.Gatherer.FRTransitionalContext} context - * @param {LH.Artifacts.NetworkRequest[]} networkRecords - * @return {LH.Artifacts['LinkElements']} + * @param {LH.Artifacts['DevtoolsLog']} devtoolsLog + * @return {Promise} */ - static getLinkElementsInHeaders(context, networkRecords) { - const finalUrl = context.url; - const mainDocument = NetworkAnalyzer.findMainDocument(networkRecords, finalUrl); + static async getLinkElementsInHeaders(context, devtoolsLog) { + const mainDocument = + await MainResource.request({devtoolsLog, URL: context.baseArtifacts.URL}, context); /** @type {LH.Artifacts['LinkElements']} */ const linkElements = []; @@ -130,7 +129,7 @@ class LinkElements extends FRGatherer { for (const link of LinkHeader.parse(header.value).refs) { linkElements.push({ rel: link.rel || '', - href: normalizeUrlOrNull(link.uri, finalUrl), + href: normalizeUrlOrNull(link.uri, context.baseArtifacts.URL.finalUrl), hrefRaw: link.uri || '', hreflang: link.hreflang || '', as: link.as || '', @@ -146,12 +145,12 @@ class LinkElements extends FRGatherer { /** * @param {LH.Gatherer.FRTransitionalContext} context - * @param {LH.Artifacts.NetworkRequest[]} networkRecords + * @param {LH.Artifacts['DevtoolsLog']} devtoolsLog * @return {Promise} */ - async _getArtifact(context, networkRecords) { + async _getArtifact(context, devtoolsLog) { const fromDOM = await LinkElements.getLinkElementsInDOM(context); - const fromHeaders = LinkElements.getLinkElementsInHeaders(context, networkRecords); + const fromHeaders = await LinkElements.getLinkElementsInHeaders(context, devtoolsLog); const linkElements = fromDOM.concat(fromHeaders); for (const link of linkElements) { @@ -168,7 +167,7 @@ class LinkElements extends FRGatherer { * @return {Promise} */ async afterPass(context, loadData) { - return this._getArtifact({...context, dependencies: {}}, loadData.networkRecords); + return this._getArtifact({...context, dependencies: {}}, loadData.devtoolsLog); } /** @@ -176,8 +175,7 @@ class LinkElements extends FRGatherer { * @return {Promise} */ async getArtifact(context) { - const records = await NetworkRecords.request(context.dependencies.DevtoolsLog, context); - return this._getArtifact(context, records); + return this._getArtifact(context, context.dependencies.DevtoolsLog); } } diff --git a/lighthouse-core/gather/gatherers/main-document-content.js b/lighthouse-core/gather/gatherers/main-document-content.js index 1f9b1fee9790..ad78f1e34019 100644 --- a/lighthouse-core/gather/gatherers/main-document-content.js +++ b/lighthouse-core/gather/gatherers/main-document-content.js @@ -6,10 +6,9 @@ 'use strict'; const FRGatherer = require('../../fraggle-rock/gather/base-gatherer.js'); -const NetworkAnalyzer = require('../../lib/dependency-graph/simulator/network-analyzer.js'); -const NetworkRecords = require('../../computed/network-records.js'); const DevtoolsLog = require('./devtools-log.js'); const {fetchResponseBodyFromCache} = require('../driver/network.js'); +const MainResource = require('../../computed/main-resource.js'); /** * Collects the content of the main html document. @@ -24,14 +23,16 @@ class MainDocumentContent extends FRGatherer { /** * * @param {LH.Gatherer.FRTransitionalContext} context - * @param {LH.Artifacts.NetworkRequest[]} networkRecords + * @param {LH.Artifacts['DevtoolsLog']} devtoolsLog * @return {Promise} */ - async _getArtifact(context, networkRecords) { - const mainResource = NetworkAnalyzer.findMainDocument(networkRecords, context.url); + async _getArtifact(context, devtoolsLog) { + const mainResource = + await MainResource.request({devtoolsLog, URL: context.baseArtifacts.URL}, context); const session = context.driver.defaultSession; return fetchResponseBodyFromCache(session, mainResource.requestId); } + /** * * @param {LH.Gatherer.FRTransitionalContext<'DevtoolsLog'>} context @@ -39,8 +40,7 @@ class MainDocumentContent extends FRGatherer { */ async getArtifact(context) { const devtoolsLog = context.dependencies.DevtoolsLog; - const networkRecords = await NetworkRecords.request(devtoolsLog, context); - return this._getArtifact(context, networkRecords); + return this._getArtifact(context, devtoolsLog); } /** @@ -49,7 +49,7 @@ class MainDocumentContent extends FRGatherer { * @return {Promise} */ async afterPass(passContext, loadData) { - return this._getArtifact({...passContext, dependencies: {}}, loadData.networkRecords); + return this._getArtifact({...passContext, dependencies: {}}, loadData.devtoolsLog); } } diff --git a/lighthouse-core/lib/script-helpers.js b/lighthouse-core/lib/script-helpers.js index fc7fa26e3a0c..250b9520202b 100644 --- a/lighthouse-core/lib/script-helpers.js +++ b/lighthouse-core/lib/script-helpers.js @@ -7,11 +7,10 @@ /** * @param {LH.Artifacts.NetworkRequest[]} networkRecords - * @param {LH.Artifacts.Script|undefined} script + * @param {LH.Artifacts.Script} script * @return {LH.Artifacts.NetworkRequest|undefined} */ function getRequestForScript(networkRecords, script) { - if (!script) return; let networkRequest = networkRecords.find(request => request.url === script.url); while (networkRequest?.redirectDestination) { networkRequest = networkRequest.redirectDestination; diff --git a/lighthouse-core/test/audits/diagnostics-test.js b/lighthouse-core/test/audits/diagnostics-test.js index 4bbfe26bf3a6..3ade72fefa73 100644 --- a/lighthouse-core/test/audits/diagnostics-test.js +++ b/lighthouse-core/test/audits/diagnostics-test.js @@ -17,6 +17,9 @@ describe('Diagnostics audit', () => { const artifacts = { traces: {defaultPass: acceptableTrace}, devtoolsLogs: {defaultPass: acceptableDevToolsLog}, + URL: { + finalUrl: 'https://pwa.rocks/', + }, }; const result = await Diagnostics.audit(artifacts, {computedCache: new Map()}); diff --git a/lighthouse-core/test/audits/server-response-time-test.js b/lighthouse-core/test/audits/server-response-time-test.js index 90ba34799cf7..4c4bdbd4086c 100644 --- a/lighthouse-core/test/audits/server-response-time-test.js +++ b/lighthouse-core/test/audits/server-response-time-test.js @@ -56,44 +56,7 @@ describe('Performance: server-response-time audit', () => { }); }); - it('identifies main resource in timespan mode', async () => { - const mainResource = { - url: 'https://example.com/', - requestId: '0', - timing: {receiveHeadersEnd: 400, sendEnd: 200}, - }; - const devtoolsLog = networkRecordsToDevtoolsLog([mainResource]); - - const artifacts = { - devtoolsLogs: {[ServerResponseTime.DEFAULT_PASS]: devtoolsLog}, - URL: {finalUrl: 'https://example.com/'}, - GatherContext: {gatherMode: 'timespan'}, - }; - - const result = await ServerResponseTime.audit(artifacts, {computedCache: new Map()}); - expect(result).toMatchObject({ - numericValue: 200, - score: 1, - }); - }); - - it('result is n/a if no main resource in timespan', async () => { - const devtoolsLog = networkRecordsToDevtoolsLog([]); - - const artifacts = { - devtoolsLogs: {[ServerResponseTime.DEFAULT_PASS]: devtoolsLog}, - URL: {finalUrl: 'https://example.com/'}, - GatherContext: {gatherMode: 'timespan'}, - }; - - const result = await ServerResponseTime.audit(artifacts, {computedCache: new Map()}); - expect(result).toEqual({ - score: null, - notApplicable: true, - }); - }); - - it('throws error if no main resource in navigation', async () => { + it('throws error if no main resource', async () => { const devtoolsLog = networkRecordsToDevtoolsLog([]); const artifacts = { diff --git a/lighthouse-core/test/fixtures/fraggle-rock/reports/sample-flow-result.json b/lighthouse-core/test/fixtures/fraggle-rock/reports/sample-flow-result.json index d85a04076248..f6c711d1176d 100644 --- a/lighthouse-core/test/fixtures/fraggle-rock/reports/sample-flow-result.json +++ b/lighthouse-core/test/fixtures/fraggle-rock/reports/sample-flow-result.json @@ -7566,13 +7566,6 @@ "items": [] } }, - "server-response-time": { - "id": "server-response-time", - "title": "Initial server response time was short", - "description": "Keep the server response time for the main document short because all other requests depend on it. [Learn more](https://web.dev/time-to-first-byte/).", - "score": null, - "scoreDisplayMode": "notApplicable" - }, "user-timings": { "id": "user-timings", "title": "User Timing marks and measures", @@ -9131,10 +9124,6 @@ "id": "uses-text-compression", "weight": 0 }, - { - "id": "server-response-time", - "weight": 0 - }, { "id": "efficient-animated-content", "weight": 0 @@ -9562,163 +9551,163 @@ }, { "startTime": 30, - "name": "lh:audit:server-response-time", + "name": "lh:audit:user-timings", "duration": 1, "entryType": "measure" }, { "startTime": 31, - "name": "lh:audit:user-timings", + "name": "lh:computed:UserTimings", "duration": 1, "entryType": "measure" }, { "startTime": 32, - "name": "lh:computed:UserTimings", + "name": "lh:audit:image-aspect-ratio", "duration": 1, "entryType": "measure" }, { "startTime": 33, - "name": "lh:audit:image-aspect-ratio", + "name": "lh:audit:image-size-responsive", "duration": 1, "entryType": "measure" }, { "startTime": 34, - "name": "lh:audit:image-size-responsive", + "name": "lh:audit:preload-fonts", "duration": 1, "entryType": "measure" }, { "startTime": 35, - "name": "lh:audit:preload-fonts", + "name": "lh:audit:deprecations", "duration": 1, "entryType": "measure" }, { "startTime": 36, - "name": "lh:audit:deprecations", + "name": "lh:audit:mainthread-work-breakdown", "duration": 1, "entryType": "measure" }, { "startTime": 37, - "name": "lh:audit:mainthread-work-breakdown", + "name": "lh:computed:MainThreadTasks", "duration": 1, "entryType": "measure" }, { "startTime": 38, - "name": "lh:computed:MainThreadTasks", + "name": "lh:audit:bootup-time", "duration": 1, "entryType": "measure" }, { "startTime": 39, - "name": "lh:audit:bootup-time", + "name": "lh:audit:network-requests", "duration": 1, "entryType": "measure" }, { "startTime": 40, - "name": "lh:audit:network-requests", + "name": "lh:audit:network-rtt", "duration": 1, "entryType": "measure" }, { "startTime": 41, - "name": "lh:audit:network-rtt", + "name": "lh:computed:NetworkAnalysis", "duration": 1, "entryType": "measure" }, { "startTime": 42, - "name": "lh:computed:NetworkAnalysis", + "name": "lh:audit:network-server-latency", "duration": 1, "entryType": "measure" }, { "startTime": 43, - "name": "lh:audit:network-server-latency", + "name": "lh:audit:main-thread-tasks", "duration": 1, "entryType": "measure" }, { "startTime": 44, - "name": "lh:audit:main-thread-tasks", + "name": "lh:audit:resource-summary", "duration": 1, "entryType": "measure" }, { "startTime": 45, - "name": "lh:audit:resource-summary", + "name": "lh:computed:ResourceSummary", "duration": 1, "entryType": "measure" }, { "startTime": 46, - "name": "lh:computed:ResourceSummary", + "name": "lh:audit:third-party-summary", "duration": 1, "entryType": "measure" }, { "startTime": 47, - "name": "lh:audit:third-party-summary", + "name": "lh:audit:layout-shift-elements", "duration": 1, "entryType": "measure" }, { "startTime": 48, - "name": "lh:audit:layout-shift-elements", + "name": "lh:audit:long-tasks", "duration": 1, "entryType": "measure" }, { "startTime": 49, - "name": "lh:audit:long-tasks", + "name": "lh:audit:no-unload-listeners", "duration": 1, "entryType": "measure" }, { "startTime": 50, - "name": "lh:audit:no-unload-listeners", + "name": "lh:audit:non-composited-animations", "duration": 1, "entryType": "measure" }, { "startTime": 51, - "name": "lh:audit:non-composited-animations", + "name": "lh:audit:unsized-images", "duration": 1, "entryType": "measure" }, { "startTime": 52, - "name": "lh:audit:unsized-images", + "name": "lh:audit:valid-source-maps", "duration": 1, "entryType": "measure" }, { "startTime": 53, - "name": "lh:audit:valid-source-maps", + "name": "lh:audit:full-page-screenshot", "duration": 1, "entryType": "measure" }, { "startTime": 54, - "name": "lh:audit:full-page-screenshot", + "name": "lh:audit:script-treemap-data", "duration": 1, "entryType": "measure" }, { "startTime": 55, - "name": "lh:audit:script-treemap-data", + "name": "lh:computed:ModuleDuplication", "duration": 1, "entryType": "measure" }, { "startTime": 56, - "name": "lh:computed:ModuleDuplication", + "name": "lh:computed:UnusedJavascriptSummary", "duration": 1, "entryType": "measure" }, @@ -9736,132 +9725,126 @@ }, { "startTime": 59, - "name": "lh:computed:UnusedJavascriptSummary", - "duration": 1, - "entryType": "measure" - }, - { - "startTime": 60, "name": "lh:audit:uses-long-cache-ttl", "duration": 1, "entryType": "measure" }, { - "startTime": 61, + "startTime": 60, "name": "lh:audit:total-byte-weight", "duration": 1, "entryType": "measure" }, { - "startTime": 62, + "startTime": 61, "name": "lh:audit:unminified-css", "duration": 1, "entryType": "measure" }, { - "startTime": 63, + "startTime": 62, "name": "lh:computed:LoadSimulator", "duration": 1, "entryType": "measure" }, { - "startTime": 64, + "startTime": 63, "name": "lh:audit:unminified-javascript", "duration": 1, "entryType": "measure" }, { - "startTime": 65, + "startTime": 64, "name": "lh:audit:unused-css-rules", "duration": 1, "entryType": "measure" }, { - "startTime": 66, + "startTime": 65, "name": "lh:computed:UnusedCSS", "duration": 1, "entryType": "measure" }, { - "startTime": 67, + "startTime": 66, "name": "lh:audit:unused-javascript", "duration": 1, "entryType": "measure" }, { - "startTime": 68, + "startTime": 67, "name": "lh:audit:modern-image-formats", "duration": 1, "entryType": "measure" }, { - "startTime": 69, + "startTime": 68, "name": "lh:audit:uses-optimized-images", "duration": 1, "entryType": "measure" }, { - "startTime": 70, + "startTime": 69, "name": "lh:audit:uses-text-compression", "duration": 1, "entryType": "measure" }, { - "startTime": 71, + "startTime": 70, "name": "lh:audit:uses-responsive-images", "duration": 1, "entryType": "measure" }, { - "startTime": 72, + "startTime": 71, "name": "lh:computed:ImageRecords", "duration": 1, "entryType": "measure" }, { - "startTime": 73, + "startTime": 72, "name": "lh:audit:efficient-animated-content", "duration": 1, "entryType": "measure" }, { - "startTime": 74, + "startTime": 73, "name": "lh:audit:duplicated-javascript", "duration": 1, "entryType": "measure" }, { - "startTime": 75, + "startTime": 74, "name": "lh:audit:legacy-javascript", "duration": 1, "entryType": "measure" }, { - "startTime": 76, + "startTime": 75, "name": "lh:audit:inspector-issues", "duration": 1, "entryType": "measure" }, { - "startTime": 77, + "startTime": 76, "name": "lh:audit:no-document-write", "duration": 1, "entryType": "measure" }, { - "startTime": 78, + "startTime": 77, "name": "lh:audit:uses-passive-event-listeners", "duration": 1, "entryType": "measure" }, { - "startTime": 79, + "startTime": 78, "name": "lh:runner:generate", "duration": 1, "entryType": "measure" } ], - "total": 80 + "total": 79 }, "i18n": { "rendererFormattedStrings": { @@ -9963,12 +9946,6 @@ "lighthouse-core/audits/errors-in-console.js | description": [ "audits[errors-in-console].description" ], - "lighthouse-core/audits/server-response-time.js | title": [ - "audits[server-response-time].title" - ], - "lighthouse-core/audits/server-response-time.js | description": [ - "audits[server-response-time].description" - ], "lighthouse-core/audits/user-timings.js | title": [ "audits[user-timings].title" ], diff --git a/lighthouse-core/test/fraggle-rock/scenarios/api-test-pptr.js b/lighthouse-core/test/fraggle-rock/scenarios/api-test-pptr.js index 46b01441b29e..7f8db2b5da97 100644 --- a/lighthouse-core/test/fraggle-rock/scenarios/api-test-pptr.js +++ b/lighthouse-core/test/fraggle-rock/scenarios/api-test-pptr.js @@ -79,10 +79,9 @@ describe('Fraggle Rock API', () => { notApplicableAudits, } = getAuditsBreakdown(lhr); // TODO(FR-COMPAT): This assertion can be removed when full compatibility is reached. - expect(auditResults.length).toMatchInlineSnapshot(`45`); + expect(auditResults.length).toMatchInlineSnapshot(`44`); expect(notApplicableAudits.length).toMatchInlineSnapshot(`5`); - expect(notApplicableAudits.map(audit => audit.id)).not.toContain('server-response-time'); expect(notApplicableAudits.map(audit => audit.id)).not.toContain('total-blocking-time'); expect(erroredAudits).toHaveLength(0); @@ -123,10 +122,9 @@ describe('Fraggle Rock API', () => { if (!result) throw new Error('Lighthouse failed to produce a result'); const {auditResults, erroredAudits, notApplicableAudits} = getAuditsBreakdown(result.lhr); - expect(auditResults.length).toMatchInlineSnapshot(`45`); + expect(auditResults.length).toMatchInlineSnapshot(`44`); - expect(notApplicableAudits.length).toMatchInlineSnapshot(`19`); - expect(notApplicableAudits.map(audit => audit.id)).toContain('server-response-time'); + expect(notApplicableAudits.length).toMatchInlineSnapshot(`18`); expect(notApplicableAudits.map(audit => audit.id)).not.toContain('total-blocking-time'); expect(erroredAudits).toHaveLength(0); diff --git a/lighthouse-core/test/gather/gather-runner-test.js b/lighthouse-core/test/gather/gather-runner-test.js index 4591e0ea7ab7..765b8dcdde82 100644 --- a/lighthouse-core/test/gather/gather-runner-test.js +++ b/lighthouse-core/test/gather/gather-runner-test.js @@ -144,7 +144,7 @@ afterEach(() => { }); describe('GatherRunner', function() { - it('loads a page and updates passContext.URL on redirect', () => { + it('loads a page and updates passContext urls on redirect', () => { const url1 = 'https://example.com'; const url2 = 'https://example.com/interstitial'; const driver = {}; @@ -158,10 +158,16 @@ describe('GatherRunner', function() { passConfig: { gatherers: [], }, + baseArtifacts: { + URL: { + finalUrl: url1, + }, + }, }; return GatherRunner.loadPage(driver, passContext).then(_ => { assert.equal(passContext.url, url2); + assert.equal(passContext.baseArtifacts.URL.finalUrl, url2); }); }); diff --git a/lighthouse-core/test/gather/gatherers/link-elements-test.js b/lighthouse-core/test/gather/gatherers/link-elements-test.js index 1c5354dca6bb..c42cf4b86e06 100644 --- a/lighthouse-core/test/gather/gatherers/link-elements-test.js +++ b/lighthouse-core/test/gather/gatherers/link-elements-test.js @@ -7,10 +7,14 @@ /* eslint-env jest */ +const mockMainResource = jest.fn(); +jest.mock('../../../computed/main-resource.js', () => ({request: mockMainResource})); + const LinkElements = require('../../../gather/gatherers/link-elements.js'); -const NetworkRecords = require('../../../computed/network-records.js'); -jest.mock('../../../computed/network-records.js'); +beforeEach(() => { + mockMainResource.mockReset(); +}); describe('Link Elements gatherer', () => { /** @@ -33,14 +37,19 @@ describe('Link Elements gatherer', () => { function getPassData({linkElementsInDOM = [], headers = []}) { const url = 'https://example.com'; - const loadData = {networkRecords: [{url, responseHeaders: headers, resourceType: 'Document'}]}; + mockMainResource.mockReturnValue({url, responseHeaders: headers, resourceType: 'Document'}); const driver = { executionContext: { evaluate: () => Promise.resolve(linkElementsInDOM), }, }; - const passContext = {driver, url}; - return [passContext, loadData]; + const baseArtifacts = { + URL: { + finalUrl: url, + }, + }; + const passContext = {driver, url, baseArtifacts, computedCache: new Map()}; + return [passContext, {}]; } it('returns elements from DOM', async () => { @@ -94,40 +103,3 @@ describe('Link Elements gatherer', () => { ]); }); }); - -describe('FR compat', () => { - /** @type {LinkElements} */ - let gatherer; - /** @type {any[]} */ - let networkRecords; - /** @type {any[]} */ - let devtoolsLog; - - beforeEach(() => { - networkRecords = ['1', '2']; - devtoolsLog = ['3', '4']; - gatherer = new LinkElements(); - gatherer._getArtifact = jest.fn(); - NetworkRecords.request = jest.fn().mockReturnValue(Promise.resolve(networkRecords)); - }); - - it('uses loadData in legacy mode', async () => { - const context = { - computedCache: new Map(), - dependencies: {}, - }; - await gatherer.afterPass(context, {networkRecords, devtoolsLog}); - expect(gatherer._getArtifact).toHaveBeenCalledWith(context, networkRecords); - expect(NetworkRecords.request).not.toHaveBeenCalled(); - }); - - it('uses dependency in FR', async () => { - const context = { - computedCache: new Map(), - dependencies: {DevtoolsLog: devtoolsLog}, - }; - await gatherer.getArtifact(context); - expect(gatherer._getArtifact).toHaveBeenCalledWith(context, networkRecords); - expect(NetworkRecords.request).toHaveBeenCalledWith(devtoolsLog, context); - }); -}); diff --git a/third-party/chromium-webtests/webtests/http/tests/devtools/lighthouse/lighthouse-successful-navigation-expected.txt b/third-party/chromium-webtests/webtests/http/tests/devtools/lighthouse/lighthouse-successful-navigation-expected.txt index a58f871acd42..59e5be64f5f5 100644 --- a/third-party/chromium-webtests/webtests/http/tests/devtools/lighthouse/lighthouse-successful-navigation-expected.txt +++ b/third-party/chromium-webtests/webtests/http/tests/devtools/lighthouse/lighthouse-successful-navigation-expected.txt @@ -30,8 +30,9 @@ Cleaning origin data Cleaning browser cache Preparing network conditions Navigating to http://127.0.0.1:8000/devtools/lighthouse/resources/lighthouse-basic.html -Computing artifact: NetworkRecords$M +Computing artifact: NetworkRecords$I Get webapp installability errors +Computing artifact: MainResource$k Getting browser version Collect stacks Computing artifact: ProcessedTrace$f @@ -74,7 +75,6 @@ Computing artifact: CumulativeLayoutShift$2 Auditing: No browser errors logged to the console Computing artifact: JSBundles Auditing: Initial server response time was short -Computing artifact: MainResource$g Auditing: Time to Interactive Computing artifact: Interactive$4 Auditing: User Timing marks and measures diff --git a/third-party/chromium-webtests/webtests/http/tests/devtools/lighthouse/lighthouse-successful-run-expected.txt b/third-party/chromium-webtests/webtests/http/tests/devtools/lighthouse/lighthouse-successful-run-expected.txt index 3b8f8993efcc..909880619b96 100644 --- a/third-party/chromium-webtests/webtests/http/tests/devtools/lighthouse/lighthouse-successful-run-expected.txt +++ b/third-party/chromium-webtests/webtests/http/tests/devtools/lighthouse/lighthouse-successful-run-expected.txt @@ -96,7 +96,7 @@ Gathering in-page: SourceMaps Gathering in-page: FullPageScreenshot Gathering trace Gathering devtoolsLog & network records -Computing artifact: NetworkRecords$M +Computing artifact: NetworkRecords$I Running afterPass methods Gathering: CSSUsage Gathering: JsUsage @@ -105,6 +105,7 @@ Gathering: ConsoleMessages Gathering: AnchorElements Gathering: ImageElements Gathering: LinkElements +Computing artifact: MainResource$k Gathering: MetaElements Gathering: ScriptElements Gathering: Scripts @@ -145,7 +146,7 @@ Navigating to http://127.0.0.1:8000/devtools/lighthouse/resources/lighthouse-bas Running pass methods Gathering in-page: ServiceWorker Gathering devtoolsLog & network records -Computing artifact: NetworkRecords$M +Computing artifact: NetworkRecords$I Running afterPass methods Gathering: ServiceWorker Disconnecting from browser... @@ -187,7 +188,6 @@ Computing artifact: CumulativeLayoutShift$2 Auditing: No browser errors logged to the console Computing artifact: JSBundles Auditing: Initial server response time was short -Computing artifact: MainResource$g Auditing: Time to Interactive Computing artifact: Interactive$4 Auditing: User Timing marks and measures