diff --git a/core/audits/byte-efficiency/render-blocking-resources.js b/core/audits/byte-efficiency/render-blocking-resources.js index c5e8d94eddee..fea0d923327a 100644 --- a/core/audits/byte-efficiency/render-blocking-resources.js +++ b/core/audits/byte-efficiency/render-blocking-resources.js @@ -38,10 +38,10 @@ const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings); /** * Given a simulation's nodeTimings, return an object with the nodes/timing keyed by network URL * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings - * @return {Map} + * @return {Map} */ function getNodesAndTimingByRequestId(nodeTimings) { - /** @type {Map} */ + /** @type {Map} */ const requestIdToNode = new Map(); for (const [node, nodeTiming] of nodeTimings) { @@ -169,7 +169,7 @@ class RenderBlockingResources extends Audit { results.push({ url: resource.args.data.url, - totalBytes: resource.args.data.encodedDataLength, + totalBytes: node.request.transferSize, wastedMs, }); } diff --git a/core/test/audits/byte-efficiency/render-blocking-resources-test.js b/core/test/audits/byte-efficiency/render-blocking-resources-test.js index e952c6f89e76..8c44d2398c7f 100644 --- a/core/test/audits/byte-efficiency/render-blocking-resources-test.js +++ b/core/test/audits/byte-efficiency/render-blocking-resources-test.js @@ -17,6 +17,8 @@ const {Simulator} = Lantern.Simulation; const trace = readJson('../../fixtures/artifacts/render-blocking/trace.json', import.meta); const devtoolsLog = readJson('../../fixtures/artifacts/render-blocking/devtoolslog.json', import.meta); +const lrTrace = readJson('../../fixtures/artifacts/lr/trace.json.gz', import.meta); +const lrDevtoolsLog = readJson('../../fixtures/artifacts/lr/devtoolslog.json.gz', import.meta); const mobileSlow4G = constants.throttling.mobileSlow4G; @@ -38,6 +40,47 @@ describe('Render blocking resources audit', () => { assert.deepStrictEqual(result.metricSavings, {FCP: 300, LCP: 0}); }); + describe('Lightrider', () => { + before(() => { + global.isLightrider = true; + }); + + after(() => { + global.isLightrider = undefined; + }); + + it('considers X-TotalFetchedSize in its reported transfer size', async () => { + // TODO(15841): The trace backend knows nothing of Lantern. + if (process.env.INTERNAL_LANTERN_USE_TRACE !== undefined) { + return; + } + + const artifacts = { + URL: getURLArtifactFromDevtoolsLog(lrDevtoolsLog), + GatherContext: {gatherMode: 'navigation'}, + traces: {defaultPass: lrTrace}, + devtoolsLogs: {defaultPass: lrDevtoolsLog}, + Stacks: [], + }; + + const settings = {throttlingMethod: 'simulate', throttling: mobileSlow4G}; + const computedCache = new Map(); + const result = await RenderBlockingResourcesAudit.audit(artifacts, {settings, computedCache}); + expect(result.details.items).toMatchInlineSnapshot(` + Array [ + Object { + "totalBytes": 128188, + "url": "https://www.llentab.cz/wp-content/uploads/fusion-styles/715df3f482419a9ed822189df6e57839.min.css?ver=3.11.10", + "wastedMs": 750, + }, + ] + `); + assert.equal(result.score, 0); + assert.equal(result.numericValue, 0); + assert.deepStrictEqual(result.metricSavings, {FCP: 0, LCP: 0}); + }); + }); + it('evaluates correct wastedMs when LCP is text', async () => { const textLcpTrace = JSON.parse(JSON.stringify(trace)); diff --git a/core/test/fixtures/artifacts/lr/devtoolslog.json.gz b/core/test/fixtures/artifacts/lr/devtoolslog.json.gz new file mode 100644 index 000000000000..03ce7efb4384 Binary files /dev/null and b/core/test/fixtures/artifacts/lr/devtoolslog.json.gz differ diff --git a/core/test/fixtures/artifacts/lr/trace.json.gz b/core/test/fixtures/artifacts/lr/trace.json.gz new file mode 100644 index 000000000000..adf41e76679b Binary files /dev/null and b/core/test/fixtures/artifacts/lr/trace.json.gz differ diff --git a/core/test/results/sample_v2.json b/core/test/results/sample_v2.json index 3bb96b2184bd..4100e87395e7 100644 --- a/core/test/results/sample_v2.json +++ b/core/test/results/sample_v2.json @@ -4496,7 +4496,7 @@ }, { "url": "http://localhost:10200/dobetterweb/unknown404.css?delay=200", - "totalBytes": 0, + "totalBytes": 235, "wastedMs": 881 }, { @@ -4516,7 +4516,7 @@ }, { "url": "http://localhost:10200/dobetterweb/fcp-delayer.js?delay=5000", - "totalBytes": 0, + "totalBytes": 249, "wastedMs": 881 } ],