From 749a57be7ba72573de1cf70e03b3f8cef99c2bcc Mon Sep 17 00:00:00 2001 From: Adam Raine Date: Wed, 26 May 2021 16:22:33 -0400 Subject: [PATCH 1/6] settings --- lighthouse-core/fraggle-rock/config/config.js | 8 ++++ .../fraggle-rock/config/default-config.js | 3 ++ lighthouse-core/gather/gatherers/settings.js | 37 +++++++++++++++++++ .../test/fraggle-rock/config/config-test.js | 22 +++++++++++ types/artifacts.d.ts | 2 + 5 files changed, 72 insertions(+) create mode 100644 lighthouse-core/gather/gatherers/settings.js diff --git a/lighthouse-core/fraggle-rock/config/config.js b/lighthouse-core/fraggle-rock/config/config.js index feabb311d0d8..8dc696326a25 100644 --- a/lighthouse-core/fraggle-rock/config/config.js +++ b/lighthouse-core/fraggle-rock/config/config.js @@ -24,6 +24,7 @@ const { resolveAuditsToDefns, resolveGathererToDefn, } = require('../../config/config-helpers.js'); +const Settings = require('../../gather/gatherers/settings.js'); const defaultConfigPath = path.join(__dirname, './default-config.js'); /** @@ -174,6 +175,13 @@ function initializeConfig(configJSON, context) { // TODO(FR-COMPAT): handle config plugins const settings = resolveSettings(configWorkingCopy.settings || {}, context.settingsOverrides); + if (configWorkingCopy.artifacts) { + const settingsArtifact = configWorkingCopy.artifacts.find(a => a.id === 'Settings'); + if (settingsArtifact) { + settingsArtifact.gatherer = {instance: new Settings(settings)}; + } + } + const artifacts = resolveArtifactsToDefns(configWorkingCopy.artifacts, configDir); const navigations = resolveNavigationsToDefns(configWorkingCopy.navigations, artifacts); diff --git a/lighthouse-core/fraggle-rock/config/default-config.js b/lighthouse-core/fraggle-rock/config/default-config.js index 999213ef303a..6c4297bbfb65 100644 --- a/lighthouse-core/fraggle-rock/config/default-config.js +++ b/lighthouse-core/fraggle-rock/config/default-config.js @@ -37,6 +37,7 @@ const artifacts = { PasswordInputsWithPreventedPaste: '', ResponseCompression: '', RobotsTxt: '', + Settings: '', SourceMaps: '', Stacks: '', TagsBlockingFirstPaint: '', @@ -56,6 +57,7 @@ for (const key of Object.keys(artifacts)) { const defaultConfig = { artifacts: [ // Artifacts which can be depended on come first. + {id: artifacts.Settings, gatherer: 'settings'}, {id: artifacts.DevtoolsLog, gatherer: 'devtools-log'}, {id: artifacts.Trace, gatherer: 'trace'}, @@ -107,6 +109,7 @@ const defaultConfig = { cpuQuietThresholdMs: 1000, artifacts: [ // Artifacts which can be depended on come first. + artifacts.Settings, artifacts.DevtoolsLog, artifacts.Trace, diff --git a/lighthouse-core/gather/gatherers/settings.js b/lighthouse-core/gather/gatherers/settings.js new file mode 100644 index 000000000000..b74b7f1ef7d2 --- /dev/null +++ b/lighthouse-core/gather/gatherers/settings.js @@ -0,0 +1,37 @@ +/** + * @license Copyright 2021 The Lighthouse Authors. All Rights Reserved. + * 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 + * 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. + */ +'use strict'; + +const FRGatherer = require('../../fraggle-rock/gather/base-gatherer.js'); + +class Settings extends FRGatherer { + static symbol = Symbol('Settings'); + + /** @type {LH.Gatherer.GathererMeta} */ + meta = { + symbol: Settings.symbol, + supportedModes: ['snapshot', 'timespan', 'navigation'], + }; + + /** + * @param {LH.Config.Settings=} settings + */ + constructor(settings) { + super(); + this._settings = settings; + } + + /** + * @return {Promise} + */ + async getArtifact() { + if (!this._settings) throw new Error('Settings artifact was not initialized'); + return this._settings; + } +} + +module.exports = Settings; + diff --git a/lighthouse-core/test/fraggle-rock/config/config-test.js b/lighthouse-core/test/fraggle-rock/config/config-test.js index 9875bc0040b1..4f77726c53f2 100644 --- a/lighthouse-core/test/fraggle-rock/config/config-test.js +++ b/lighthouse-core/test/fraggle-rock/config/config-test.js @@ -53,6 +53,28 @@ describe('Fraggle Rock Config', () => { }); }); + it('should resolve settings artifact', () => { + const {config} = initializeConfig( + { + settings: {output: 'csv', maxWaitForFcp: 1234}, + artifacts: [{id: 'Settings', gatherer: 'settings'}], + }, + {gatherMode} + ); + if (!config.artifacts) throw new Error('Did not define artifacts'); + expect(config.artifacts).toHaveLength(1); + expect(config.artifacts[0].gatherer).toMatchObject({ + instance: { + _settings: { + output: 'csv', + maxWaitForFcp: 1234, + }, + }, + implementation: undefined, + path: undefined, + }); + }); + it('should resolve artifact definitions', () => { const configJson = {artifacts: [{id: 'Accessibility', gatherer: 'accessibility'}]}; const {config} = initializeConfig(configJson, {gatherMode}); diff --git a/types/artifacts.d.ts b/types/artifacts.d.ts index a21cc5b42fcb..e8f5e3539277 100644 --- a/types/artifacts.d.ts +++ b/types/artifacts.d.ts @@ -163,6 +163,8 @@ declare global { ResponseCompression: {requestId: string, url: string, mimeType: string, transferSize: number, resourceSize: number, gzipSize?: number}[]; /** Information on fetching and the content of the /robots.txt file. */ RobotsTxt: {status: number|null, content: string|null}; + /** An object containing information about the testing configuration used by Lighthouse. */ + Settings: Config.Settings; /** Version information for all ServiceWorkers active after the first page load. */ ServiceWorker: {versions: Crdp.ServiceWorker.ServiceWorkerVersion[], registrations: Crdp.ServiceWorker.ServiceWorkerRegistration[]}; /** Source maps of scripts executed in the page. */ From 2e1a75298f5b7b4a2cbd133a29d1b66dbfb3c2fa Mon Sep 17 00:00:00 2001 From: Adam Raine Date: Wed, 26 May 2021 18:53:05 -0400 Subject: [PATCH 2/6] convert screenshot --- .../gather/gatherers/full-page-screenshot.js | 81 ++++--- .../test/fraggle-rock/gather/mock-driver.js | 6 +- .../gatherers/full-page-screenshot-test.js | 226 +++++++++--------- 3 files changed, 166 insertions(+), 147 deletions(-) diff --git a/lighthouse-core/gather/gatherers/full-page-screenshot.js b/lighthouse-core/gather/gatherers/full-page-screenshot.js index 6170f9297fb7..ce7d15ba0d12 100644 --- a/lighthouse-core/gather/gatherers/full-page-screenshot.js +++ b/lighthouse-core/gather/gatherers/full-page-screenshot.js @@ -7,11 +7,10 @@ /* globals window document getBoundingClientRect */ -const Gatherer = require('./gatherer.js'); +const FRGatherer = require('../../fraggle-rock/gather/base-gatherer.js'); const emulation = require('../../lib/emulation.js'); const pageFunctions = require('../../lib/page-functions.js'); - -/** @typedef {import('../driver.js')} Driver */ +const Settings = require('./settings.js'); // JPEG quality setting // Exploration and examples of reports using different quality settings: https://docs.google.com/document/d/1ZSffucIca9XDW2eEwfoevrk-OTl7WQFeMf0CgeJAA8M/edit# @@ -24,14 +23,20 @@ function snakeCaseToCamelCase(str) { return str.replace(/(-\w)/g, m => m[1].toUpperCase()); } -class FullPageScreenshot extends Gatherer { +class FullPageScreenshot extends FRGatherer { + /** @type {LH.Gatherer.GathererMeta<'Settings'>} */ + meta = { + supportedModes: ['snapshot', 'timespan', 'navigation'], + dependencies: {Settings: Settings.symbol}, + } + /** - * @param {Driver} driver + * @param {LH.Gatherer.FRTransitionalContext} context * @return {Promise} * @see https://bugs.chromium.org/p/chromium/issues/detail?id=770769 */ - async getMaxScreenshotHeight(driver) { - return await driver.executionContext.evaluate(pageFunctions.getMaxTextureSize, { + async getMaxScreenshotHeight(context) { + return await context.driver.executionContext.evaluate(pageFunctions.getMaxTextureSize, { args: [], useIsolation: true, deps: [], @@ -39,13 +44,14 @@ class FullPageScreenshot extends Gatherer { } /** - * @param {LH.Gatherer.PassContext} passContext + * @param {LH.Gatherer.FRTransitionalContext} context + * @param {LH.Config.Settings} settings * @return {Promise} */ - async _takeScreenshot(passContext) { - const driver = passContext.driver; - const maxScreenshotHeight = await this.getMaxScreenshotHeight(driver); - const metrics = await driver.sendCommand('Page.getLayoutMetrics'); + async _takeScreenshot(context, settings) { + const session = context.driver.defaultSession; + const maxScreenshotHeight = await this.getMaxScreenshotHeight(context); + const metrics = await session.sendCommand('Page.getLayoutMetrics'); // Width should match emulated width, without considering content overhang. // Both layoutViewport and visualViewport capture this. visualViewport accounts @@ -56,9 +62,9 @@ class FullPageScreenshot extends Gatherer { const width = Math.min(metrics.layoutViewport.clientWidth, maxScreenshotHeight); const height = Math.min(metrics.contentSize.height, maxScreenshotHeight); - await driver.sendCommand('Emulation.setDeviceMetricsOverride', { + await session.sendCommand('Emulation.setDeviceMetricsOverride', { // If we're gathering with mobile screenEmulation on (overlay scrollbars, etc), continue to use that for this screenshot. - mobile: passContext.settings.screenEmulation.mobile, + mobile: settings.screenEmulation.mobile, height, width, deviceScaleFactor: 1, @@ -70,7 +76,7 @@ class FullPageScreenshot extends Gatherer { // The lower in the page, the more likely (footer elements especially). // https://github.com/GoogleChrome/lighthouse/issues/11118 - const result = await driver.sendCommand('Page.captureScreenshot', { + const result = await session.sendCommand('Page.captureScreenshot', { format: 'jpeg', quality: FULL_PAGE_SCREENSHOT_QUALITY, }); @@ -90,10 +96,10 @@ class FullPageScreenshot extends Gatherer { * `getNodeDetails` maintains a collection of DOM objects in the page, which we can iterate * to re-collect the bounding client rectangle. * @see pageFunctions.getNodeDetails - * @param {LH.Gatherer.PassContext} passContext + * @param {LH.Gatherer.FRTransitionalContext} context * @return {Promise} */ - async _resolveNodes(passContext) { + async _resolveNodes(context) { function resolveNodes() { /** @type {LH.Artifacts.FullPageScreenshot['nodes']} */ const nodes = {}; @@ -113,7 +119,7 @@ class FullPageScreenshot extends Gatherer { * @param {{useIsolation: boolean}} _ */ function resolveNodesInPage({useIsolation}) { - return passContext.driver.executionContext.evaluate(resolveNodes, { + return context.driver.executionContext.evaluate(resolveNodes, { args: [], useIsolation, deps: [pageFunctions.getBoundingClientRectString], @@ -129,26 +135,27 @@ class FullPageScreenshot extends Gatherer { } /** - * @param {LH.Gatherer.PassContext} passContext + * @param {LH.Gatherer.FRTransitionalContext} context + * @param {LH.Config.Settings} settings * @return {Promise} */ - async afterPass(passContext) { - const {driver} = passContext; - const executionContext = driver.executionContext; + async _getArtifact(context, settings) { + const session = context.driver.defaultSession; + const executionContext = context.driver.executionContext; // In case some other program is controlling emulation, try to remember what the device looks // like now and reset after gatherer is done. - const lighthouseControlsEmulation = !passContext.settings.screenEmulation.disabled; + const lighthouseControlsEmulation = !settings.screenEmulation.disabled; try { return { - screenshot: await this._takeScreenshot(passContext), - nodes: await this._resolveNodes(passContext), + screenshot: await this._takeScreenshot(context, settings), + nodes: await this._resolveNodes(context), }; } finally { // Revert resized page. if (lighthouseControlsEmulation) { - await emulation.emulate(driver.defaultSession, passContext.settings); + await emulation.emulate(session, settings); } else { // Best effort to reset emulation to what it was. // https://github.com/GoogleChrome/lighthouse/pull/10716#discussion_r428970681 @@ -179,13 +186,31 @@ class FullPageScreenshot extends Gatherer { useIsolation: true, deps: [snakeCaseToCamelCase], }); - await driver.sendCommand('Emulation.setDeviceMetricsOverride', { - mobile: passContext.settings.formFactor === 'mobile', + await session.sendCommand('Emulation.setDeviceMetricsOverride', { + mobile: settings.formFactor === 'mobile', ...observedDeviceMetrics, }); } } } + + /** + * @param {LH.Gatherer.FRTransitionalContext<'Settings'>} context + * @return {Promise} + */ + async getArtifact(context) { + const settings = context.dependencies.Settings; + return this._getArtifact(context, settings); + } + + /** + * @param {LH.Gatherer.PassContext} passContext + * @return {Promise} + */ + async afterPass(passContext) { + const settings = passContext.settings; + return this._getArtifact({...passContext, dependencies: {}}, settings); + } } module.exports = FullPageScreenshot; diff --git a/lighthouse-core/test/fraggle-rock/gather/mock-driver.js b/lighthouse-core/test/fraggle-rock/gather/mock-driver.js index 0db3a3f1dd84..c053435f9bc9 100644 --- a/lighthouse-core/test/fraggle-rock/gather/mock-driver.js +++ b/lighthouse-core/test/fraggle-rock/gather/mock-driver.js @@ -156,7 +156,10 @@ function mockDriverSubmodules() { prepareTargetForIndividualNavigation: jest.fn(), }; const storageMock = {clearDataForOrigin: jest.fn()}; - const emulationMock = {clearThrottling: jest.fn()}; + const emulationMock = { + clearThrottling: jest.fn(), + emulate: jest.fn(), + }; const networkMock = { fetchResponseBodyFromCache: jest.fn(), }; @@ -167,6 +170,7 @@ function mockDriverSubmodules() { prepareMock.prepareTargetForIndividualNavigation = jest.fn().mockResolvedValue({warnings: []}); storageMock.clearDataForOrigin = jest.fn(); emulationMock.clearThrottling = jest.fn(); + emulationMock.emulate = jest.fn(); networkMock.fetchResponseBodyFromCache = jest.fn().mockResolvedValue(''); } diff --git a/lighthouse-core/test/gather/gatherers/full-page-screenshot-test.js b/lighthouse-core/test/gather/gatherers/full-page-screenshot-test.js index d5eda847c7fb..e89a030ae1d0 100644 --- a/lighthouse-core/test/gather/gatherers/full-page-screenshot-test.js +++ b/lighthouse-core/test/gather/gatherers/full-page-screenshot-test.js @@ -7,19 +7,27 @@ /* eslint-env jest */ -let mockEmulate = jest.fn(); -jest.mock('../../../lib/emulation.js', () => ({emulate: (...args) => mockEmulate(...args)})); - +const { + createMockContext, + mockDriverSubmodules, +} = require('../../fraggle-rock/gather/mock-driver.js'); +const mocks = mockDriverSubmodules(); const FullPageScreenshotGatherer = require('../../../gather/gatherers/full-page-screenshot.js'); // Headless's default value is (1024 * 16), but this varies by device const maxTextureSizeMock = 1024 * 8; -/** - * @param {{contentSize: {width: number, height: number}, screenSize: {width?: number, height?: number, dpr: number}, screenshotData: string[]}} - */ -function createMockDriver({contentSize, screenSize, screenshotData}) { - const sendCommand = jest.fn().mockImplementation(method => { +/** @type {{width: number, height: number}} */ +let contentSize; +/** @type {{width?: number, height?: number, dpr: number}} */ +let screenSize; +/** @type {string[]} */ +let screenshotData; +let mockContext = createMockContext(); + +beforeEach(() => { + mockContext = createMockContext(); + mockContext.driver.defaultSession.sendCommand.mockImplementation(method => { if (method === 'Page.getLayoutMetrics') { return { contentSize, @@ -33,62 +41,75 @@ function createMockDriver({contentSize, screenSize, screenshotData}) { }; } }); - - return { - executionContext: { - evaluate: async function(fn) { - if (fn.name === 'resolveNodes') { - return {}; - } if (fn.name === 'getMaxTextureSize') { - return maxTextureSizeMock; - } else if (fn.name === 'getObservedDeviceMetrics') { - return { - width: screenSize.width, - height: screenSize.height, - screenWidth: screenSize.width, - screenHeight: screenSize.height, - screenOrientation: { - type: 'landscapePrimary', - angle: 30, - }, - deviceScaleFactor: screenSize.dpr, - }; - } else { - throw new Error(`unexpected fn ${fn.name}`); - } - }, - }, - sendCommand, - defaultSession: {sendCommand}, - }; -} - -describe('FullPageScreenshot gatherer', () => { - beforeEach(() => { - mockEmulate = jest.fn(); + mockContext.driver._executionContext.evaluate.mockImplementation(fn => { + if (fn.name === 'resolveNodes') { + return {}; + } if (fn.name === 'getMaxTextureSize') { + return maxTextureSizeMock; + } else if (fn.name === 'getObservedDeviceMetrics') { + return { + width: screenSize.width, + height: screenSize.height, + screenWidth: screenSize.width, + screenHeight: screenSize.height, + screenOrientation: { + type: 'landscapePrimary', + angle: 30, + }, + deviceScaleFactor: screenSize.dpr, + }; + } else { + throw new Error(`unexpected fn ${fn.name}`); + } }); + mocks.reset(); +}); - it('captures a full-page screenshot', async () => { +describe('FullPageScreenshot gatherer', () => { + it('captures a full-page screenshot in FR', async () => { const fpsGatherer = new FullPageScreenshotGatherer(); - const driver = createMockDriver({ - contentSize: { - width: 412, + contentSize = {width: 412, height: 2000}; + + const settings = { + formFactor: 'mobile', + screenEmulation: { + mobile: true, + disabled: false, + }, + }; + const context = { + ...mockContext.asContext(), + dependencies: {Settings: settings}, + }; + const artifact = await fpsGatherer.getArtifact(context); + + expect(artifact).toEqual({ + screenshot: { + data: 'data:image/jpeg;base64,abc', height: 2000, + width: 412, }, + nodes: {}, }); - const passContext = { - settings: { - formFactor: 'mobile', - screenEmulation: { - mobile: true, - disabled: false, - }, + }); + + it('captures a full-page screenshot in legacy mode', async () => { + const fpsGatherer = new FullPageScreenshotGatherer(); + contentSize = {width: 412, height: 2000}; + + const settings = { + formFactor: 'mobile', + screenEmulation: { + mobile: true, + disabled: false, }, - driver, - baseArtifacts: {}, }; + const context = { + ...mockContext.asLegacyContext(), + settings, + }; + const artifact = await fpsGatherer.afterPass(context); - const artifact = await fpsGatherer.afterPass(passContext); expect(artifact).toEqual({ screenshot: { data: 'data:image/jpeg;base64,abc', @@ -101,59 +122,39 @@ describe('FullPageScreenshot gatherer', () => { it('resets the emulation correctly when Lighthouse controls it', async () => { const fpsGatherer = new FullPageScreenshotGatherer(); - const driver = createMockDriver({ - contentSize: { - width: 412, - height: 2000, + contentSize = {width: 412, height: 2000}; + + await fpsGatherer._getArtifact(mockContext.asContext(), { + formFactor: 'mobile', + screenEmulation: { + mobile: true, + disabled: false, }, }); - const passContext = { - settings: { - formFactor: 'mobile', - screenEmulation: { - mobile: true, - disabled: false, - }, - }, - driver, - baseArtifacts: {}, - }; - - await fpsGatherer.afterPass(passContext); const expectedArgs = {formFactor: 'mobile', screenEmulation: {disabled: false, mobile: true}}; - expect(mockEmulate).toHaveBeenCalledTimes(1); - expect(mockEmulate).toHaveBeenCalledWith(driver.defaultSession, expectedArgs); + expect(mocks.emulationMock.emulate).toHaveBeenCalledTimes(1); + expect(mocks.emulationMock.emulate).toHaveBeenCalledWith( + mockContext.driver.defaultSession, + expectedArgs + ); }); it('resets the emulation correctly when Lighthouse does not control it', async () => { const fpsGatherer = new FullPageScreenshotGatherer(); - const driver = createMockDriver({ - contentSize: { - width: 500, - height: 1500, - }, - screenSize: { - width: 500, - height: 500, - dpr: 2, + contentSize = {width: 500, height: 1500}; + screenSize = {width: 500, height: 500, dpr: 2}; + + await fpsGatherer._getArtifact(mockContext.asContext(), { + screenEmulation: { + mobile: true, + disabled: true, }, + formFactor: 'mobile', }); - const passContext = { - settings: { - screenEmulation: { - mobile: true, - disabled: true, - }, - formFactor: 'mobile', - }, - driver, - }; - - await fpsGatherer.afterPass(passContext); // Setting up for screenshot. - expect(driver.sendCommand).toHaveBeenCalledWith( + expect(mockContext.driver.defaultSession.sendCommand).toHaveBeenCalledWith( 'Emulation.setDeviceMetricsOverride', expect.objectContaining({ mobile: true, @@ -164,7 +165,7 @@ describe('FullPageScreenshot gatherer', () => { ); // Restoring. - expect(driver.sendCommand).toHaveBeenCalledWith( + expect(mockContext.driver.defaultSession.sendCommand).toHaveBeenCalledWith( 'Emulation.setDeviceMetricsOverride', expect.objectContaining({ mobile: true, @@ -181,30 +182,19 @@ describe('FullPageScreenshot gatherer', () => { it('limits the screenshot height to the max Chrome can capture', async () => { const fpsGatherer = new FullPageScreenshotGatherer(); - const driver = createMockDriver({ - contentSize: { - width: 412, - height: 100000, - }, - screenSize: { - dpr: 1, + + contentSize = {width: 412, height: 100000}; + screenSize = {dpr: 1}; + + await fpsGatherer._getArtifact(mockContext.asContext(), { + formFactor: 'mobile', + screenEmulation: { + mobile: true, + disabled: false, }, }); - const passContext = { - settings: { - formFactor: 'mobile', - screenEmulation: { - mobile: true, - disabled: false, - }, - }, - driver, - baseArtifacts: {}, - }; - - await fpsGatherer.afterPass(passContext); - expect(driver.sendCommand).toHaveBeenCalledWith( + expect(mockContext.driver.defaultSession.sendCommand).toHaveBeenCalledWith( 'Emulation.setDeviceMetricsOverride', expect.objectContaining({ deviceScaleFactor: 1, From e56b915497fb9643f8507bef4180342763958464 Mon Sep 17 00:00:00 2001 From: Adam Raine Date: Thu, 27 May 2021 11:35:18 -0400 Subject: [PATCH 3/6] add to config --- lighthouse-core/fraggle-rock/config/default-config.js | 3 +++ lighthouse-core/test/fraggle-rock/api-test-pptr.js | 6 +++--- types/artifacts.d.ts | 1 - 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lighthouse-core/fraggle-rock/config/default-config.js b/lighthouse-core/fraggle-rock/config/default-config.js index 6c4297bbfb65..22503fe6f762 100644 --- a/lighthouse-core/fraggle-rock/config/default-config.js +++ b/lighthouse-core/fraggle-rock/config/default-config.js @@ -23,6 +23,7 @@ const artifacts = { EmbeddedContent: '', FontSize: '', FormElements: '', + FullPageScreenshot: '', GlobalListeners: '', IFrameElements: '', ImageElements: '', @@ -73,6 +74,7 @@ const defaultConfig = { {id: artifacts.EmbeddedContent, gatherer: 'seo/embedded-content'}, {id: artifacts.FontSize, gatherer: 'seo/font-size'}, {id: artifacts.FormElements, gatherer: 'form-elements'}, + {id: artifacts.FullPageScreenshot, gatherer: 'full-page-screenshot'}, {id: artifacts.GlobalListeners, gatherer: 'global-listeners'}, {id: artifacts.IFrameElements, gatherer: 'iframe-elements'}, {id: artifacts.ImageElements, gatherer: 'image-elements'}, @@ -124,6 +126,7 @@ const defaultConfig = { artifacts.EmbeddedContent, artifacts.FontSize, artifacts.FormElements, + artifacts.FullPageScreenshot, artifacts.GlobalListeners, artifacts.IFrameElements, artifacts.ImageElements, diff --git a/lighthouse-core/test/fraggle-rock/api-test-pptr.js b/lighthouse-core/test/fraggle-rock/api-test-pptr.js index d6313e207c0b..960a5ba623a5 100644 --- a/lighthouse-core/test/fraggle-rock/api-test-pptr.js +++ b/lighthouse-core/test/fraggle-rock/api-test-pptr.js @@ -95,7 +95,7 @@ describe('Fraggle Rock API', () => { const {auditResults, erroredAudits, failedAudits} = getAuditsBreakdown(lhr); // TODO(FR-COMPAT): This assertion can be removed when full compatibility is reached. - expect(auditResults.length).toMatchInlineSnapshot(`73`); + expect(auditResults.length).toMatchInlineSnapshot(`74`); expect(erroredAudits).toHaveLength(0); expect(failedAudits.map(audit => audit.id)).toContain('label'); @@ -121,7 +121,7 @@ describe('Fraggle Rock API', () => { const {auditResults, erroredAudits, failedAudits} = getAuditsBreakdown(lhr); // TODO(FR-COMPAT): This assertion can be removed when full compatibility is reached. - expect(auditResults.length).toMatchInlineSnapshot(`27`); + expect(auditResults.length).toMatchInlineSnapshot(`28`); expect(erroredAudits).toHaveLength(0); expect(failedAudits.map(audit => audit.id)).toContain('errors-in-console'); @@ -159,7 +159,7 @@ describe('Fraggle Rock API', () => { const {lhr} = result; const {auditResults, failedAudits, erroredAudits} = getAuditsBreakdown(lhr); // TODO(FR-COMPAT): This assertion can be removed when full compatibility is reached. - expect(auditResults.length).toMatchInlineSnapshot(`113`); + expect(auditResults.length).toMatchInlineSnapshot(`114`); expect(erroredAudits).toHaveLength(0); const failedAuditIds = failedAudits.map(audit => audit.id); diff --git a/types/artifacts.d.ts b/types/artifacts.d.ts index e8f5e3539277..e0bd2cc78cc5 100644 --- a/types/artifacts.d.ts +++ b/types/artifacts.d.ts @@ -21,7 +21,6 @@ declare global { export type FRArtifacts = StrictOmit Date: Thu, 27 May 2021 19:06:18 -0400 Subject: [PATCH 4/6] revert --- lighthouse-core/fraggle-rock/config/config.js | 8 --- .../fraggle-rock/config/default-config.js | 3 -- .../fraggle-rock/gather/navigation-runner.js | 1 + .../fraggle-rock/gather/runner-helpers.js | 12 ++++- .../fraggle-rock/gather/snapshot-runner.js | 1 + .../fraggle-rock/gather/timespan-runner.js | 1 + .../gather/gatherers/full-page-screenshot.js | 26 ++------- lighthouse-core/gather/gatherers/settings.js | 37 ------------- .../test/fraggle-rock/config/config-test.js | 26 +-------- .../test/fraggle-rock/gather/mock-driver.js | 2 + .../gather/runner-helpers-test.js | 5 ++ .../test/gather/gatherers/css-usage-test.js | 3 ++ .../gatherers/full-page-screenshot-test.js | 54 +++++-------------- types/artifacts.d.ts | 2 - types/gatherer.d.ts | 1 + 15 files changed, 43 insertions(+), 139 deletions(-) delete mode 100644 lighthouse-core/gather/gatherers/settings.js diff --git a/lighthouse-core/fraggle-rock/config/config.js b/lighthouse-core/fraggle-rock/config/config.js index 8dc696326a25..feabb311d0d8 100644 --- a/lighthouse-core/fraggle-rock/config/config.js +++ b/lighthouse-core/fraggle-rock/config/config.js @@ -24,7 +24,6 @@ const { resolveAuditsToDefns, resolveGathererToDefn, } = require('../../config/config-helpers.js'); -const Settings = require('../../gather/gatherers/settings.js'); const defaultConfigPath = path.join(__dirname, './default-config.js'); /** @@ -175,13 +174,6 @@ function initializeConfig(configJSON, context) { // TODO(FR-COMPAT): handle config plugins const settings = resolveSettings(configWorkingCopy.settings || {}, context.settingsOverrides); - if (configWorkingCopy.artifacts) { - const settingsArtifact = configWorkingCopy.artifacts.find(a => a.id === 'Settings'); - if (settingsArtifact) { - settingsArtifact.gatherer = {instance: new Settings(settings)}; - } - } - const artifacts = resolveArtifactsToDefns(configWorkingCopy.artifacts, configDir); const navigations = resolveNavigationsToDefns(configWorkingCopy.navigations, artifacts); diff --git a/lighthouse-core/fraggle-rock/config/default-config.js b/lighthouse-core/fraggle-rock/config/default-config.js index 22503fe6f762..6d2d961cec19 100644 --- a/lighthouse-core/fraggle-rock/config/default-config.js +++ b/lighthouse-core/fraggle-rock/config/default-config.js @@ -38,7 +38,6 @@ const artifacts = { PasswordInputsWithPreventedPaste: '', ResponseCompression: '', RobotsTxt: '', - Settings: '', SourceMaps: '', Stacks: '', TagsBlockingFirstPaint: '', @@ -58,7 +57,6 @@ for (const key of Object.keys(artifacts)) { const defaultConfig = { artifacts: [ // Artifacts which can be depended on come first. - {id: artifacts.Settings, gatherer: 'settings'}, {id: artifacts.DevtoolsLog, gatherer: 'devtools-log'}, {id: artifacts.Trace, gatherer: 'trace'}, @@ -111,7 +109,6 @@ const defaultConfig = { cpuQuietThresholdMs: 1000, artifacts: [ // Artifacts which can be depended on come first. - artifacts.Settings, artifacts.DevtoolsLog, artifacts.Trace, diff --git a/lighthouse-core/fraggle-rock/gather/navigation-runner.js b/lighthouse-core/fraggle-rock/gather/navigation-runner.js index 824fc9f4b276..32a0dcd50fc4 100644 --- a/lighthouse-core/fraggle-rock/gather/navigation-runner.js +++ b/lighthouse-core/fraggle-rock/gather/navigation-runner.js @@ -171,6 +171,7 @@ async function _navigation(navigationContext) { computedCache: navigationContext.computedCache, artifactDefinitions: navigationContext.navigation.artifacts, artifactState, + settings: navigationContext.config.settings, }; const setupResult = await _setupNavigation(navigationContext); diff --git a/lighthouse-core/fraggle-rock/gather/runner-helpers.js b/lighthouse-core/fraggle-rock/gather/runner-helpers.js index e3098b12e91b..07fd927c0b6b 100644 --- a/lighthouse-core/fraggle-rock/gather/runner-helpers.js +++ b/lighthouse-core/fraggle-rock/gather/runner-helpers.js @@ -13,6 +13,7 @@ * @property {LH.Gatherer.FRGatherPhase} phase * @property {LH.Gatherer.GatherMode} gatherMode * @property {Map} computedCache + * @property {LH.Config.Settings} settings */ /** @typedef {Record>} IntermediateArtifacts */ @@ -61,7 +62,15 @@ const phaseToPriorPhase = { * @param {CollectPhaseArtifactOptions} options */ async function collectPhaseArtifacts(options) { - const {driver, artifactDefinitions, artifactState, phase, gatherMode, computedCache} = options; + const { + driver, + artifactDefinitions, + artifactState, + phase, + gatherMode, + computedCache, + settings, + } = options; const priorPhase = phaseToPriorPhase[phase]; const priorPhaseArtifacts = (priorPhase && artifactState[priorPhase]) || {}; @@ -80,6 +89,7 @@ async function collectPhaseArtifacts(options) { driver, dependencies, computedCache, + settings, }); }); diff --git a/lighthouse-core/fraggle-rock/gather/snapshot-runner.js b/lighthouse-core/fraggle-rock/gather/snapshot-runner.js index 07831ad44b64..cbe01bf91f66 100644 --- a/lighthouse-core/fraggle-rock/gather/snapshot-runner.js +++ b/lighthouse-core/fraggle-rock/gather/snapshot-runner.js @@ -40,6 +40,7 @@ async function snapshot(options) { artifactDefinitions, artifactState, computedCache, + settings: config.settings, }); const artifacts = await awaitArtifacts(artifactState); diff --git a/lighthouse-core/fraggle-rock/gather/timespan-runner.js b/lighthouse-core/fraggle-rock/gather/timespan-runner.js index 8207f5f2ceb7..555b2bdcad4a 100644 --- a/lighthouse-core/fraggle-rock/gather/timespan-runner.js +++ b/lighthouse-core/fraggle-rock/gather/timespan-runner.js @@ -36,6 +36,7 @@ async function startTimespan(options) { artifactState, computedCache, gatherMode: 'timespan', + settings: config.settings, }; await collectPhaseArtifacts({phase: 'startInstrumentation', ...phaseOptions}); diff --git a/lighthouse-core/gather/gatherers/full-page-screenshot.js b/lighthouse-core/gather/gatherers/full-page-screenshot.js index ce7d15ba0d12..50518072744c 100644 --- a/lighthouse-core/gather/gatherers/full-page-screenshot.js +++ b/lighthouse-core/gather/gatherers/full-page-screenshot.js @@ -10,7 +10,6 @@ const FRGatherer = require('../../fraggle-rock/gather/base-gatherer.js'); const emulation = require('../../lib/emulation.js'); const pageFunctions = require('../../lib/page-functions.js'); -const Settings = require('./settings.js'); // JPEG quality setting // Exploration and examples of reports using different quality settings: https://docs.google.com/document/d/1ZSffucIca9XDW2eEwfoevrk-OTl7WQFeMf0CgeJAA8M/edit# @@ -24,10 +23,9 @@ function snakeCaseToCamelCase(str) { } class FullPageScreenshot extends FRGatherer { - /** @type {LH.Gatherer.GathererMeta<'Settings'>} */ + /** @type {LH.Gatherer.GathererMeta} */ meta = { supportedModes: ['snapshot', 'timespan', 'navigation'], - dependencies: {Settings: Settings.symbol}, } /** @@ -136,12 +134,12 @@ class FullPageScreenshot extends FRGatherer { /** * @param {LH.Gatherer.FRTransitionalContext} context - * @param {LH.Config.Settings} settings * @return {Promise} */ - async _getArtifact(context, settings) { + async getArtifact(context) { const session = context.driver.defaultSession; const executionContext = context.driver.executionContext; + const settings = context.settings; // In case some other program is controlling emulation, try to remember what the device looks // like now and reset after gatherer is done. @@ -193,24 +191,6 @@ class FullPageScreenshot extends FRGatherer { } } } - - /** - * @param {LH.Gatherer.FRTransitionalContext<'Settings'>} context - * @return {Promise} - */ - async getArtifact(context) { - const settings = context.dependencies.Settings; - return this._getArtifact(context, settings); - } - - /** - * @param {LH.Gatherer.PassContext} passContext - * @return {Promise} - */ - async afterPass(passContext) { - const settings = passContext.settings; - return this._getArtifact({...passContext, dependencies: {}}, settings); - } } module.exports = FullPageScreenshot; diff --git a/lighthouse-core/gather/gatherers/settings.js b/lighthouse-core/gather/gatherers/settings.js deleted file mode 100644 index b74b7f1ef7d2..000000000000 --- a/lighthouse-core/gather/gatherers/settings.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @license Copyright 2021 The Lighthouse Authors. All Rights Reserved. - * 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 - * 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. - */ -'use strict'; - -const FRGatherer = require('../../fraggle-rock/gather/base-gatherer.js'); - -class Settings extends FRGatherer { - static symbol = Symbol('Settings'); - - /** @type {LH.Gatherer.GathererMeta} */ - meta = { - symbol: Settings.symbol, - supportedModes: ['snapshot', 'timespan', 'navigation'], - }; - - /** - * @param {LH.Config.Settings=} settings - */ - constructor(settings) { - super(); - this._settings = settings; - } - - /** - * @return {Promise} - */ - async getArtifact() { - if (!this._settings) throw new Error('Settings artifact was not initialized'); - return this._settings; - } -} - -module.exports = Settings; - diff --git a/lighthouse-core/test/fraggle-rock/config/config-test.js b/lighthouse-core/test/fraggle-rock/config/config-test.js index 4f77726c53f2..4d4437657160 100644 --- a/lighthouse-core/test/fraggle-rock/config/config-test.js +++ b/lighthouse-core/test/fraggle-rock/config/config-test.js @@ -53,28 +53,6 @@ describe('Fraggle Rock Config', () => { }); }); - it('should resolve settings artifact', () => { - const {config} = initializeConfig( - { - settings: {output: 'csv', maxWaitForFcp: 1234}, - artifacts: [{id: 'Settings', gatherer: 'settings'}], - }, - {gatherMode} - ); - if (!config.artifacts) throw new Error('Did not define artifacts'); - expect(config.artifacts).toHaveLength(1); - expect(config.artifacts[0].gatherer).toMatchObject({ - instance: { - _settings: { - output: 'csv', - maxWaitForFcp: 1234, - }, - }, - implementation: undefined, - path: undefined, - }); - }); - it('should resolve artifact definitions', () => { const configJson = {artifacts: [{id: 'Accessibility', gatherer: 'accessibility'}]}; const {config} = initializeConfig(configJson, {gatherMode}); @@ -85,8 +63,8 @@ describe('Fraggle Rock Config', () => { }); it('should throw on invalid artifact definitions', () => { - const configJson = {artifacts: [{id: 'FullPageScreenshot', gatherer: 'full-page-screenshot'}]}; - expect(() => initializeConfig(configJson, {gatherMode})).toThrow(/FullPageScreenshot gatherer/); + const configJson = {artifacts: [{id: 'ScriptElements', gatherer: 'script-elements'}]}; + expect(() => initializeConfig(configJson, {gatherMode})).toThrow(/ScriptElements gatherer/); }); it('should resolve navigation definitions', () => { diff --git a/lighthouse-core/test/fraggle-rock/gather/mock-driver.js b/lighthouse-core/test/fraggle-rock/gather/mock-driver.js index c053435f9bc9..faa9aaf5138f 100644 --- a/lighthouse-core/test/fraggle-rock/gather/mock-driver.js +++ b/lighthouse-core/test/fraggle-rock/gather/mock-driver.js @@ -12,6 +12,7 @@ const { createMockOnceFn, createMockSendCommandFn, } = require('../../gather/mock-commands.js'); +const {defaultSettings} = require('../../../config/constants.js'); /** * @fileoverview Mock fraggle rock driver for testing. @@ -134,6 +135,7 @@ function createMockContext() { gatherMode: 'navigation', computedCache: new Map(), dependencies: {}, + settings: defaultSettings, /** @return {LH.Gatherer.FRTransitionalContext} */ asContext() { diff --git a/lighthouse-core/test/fraggle-rock/gather/runner-helpers-test.js b/lighthouse-core/test/fraggle-rock/gather/runner-helpers-test.js index 6d4208983b0f..3feaf1f38a98 100644 --- a/lighthouse-core/test/fraggle-rock/gather/runner-helpers-test.js +++ b/lighthouse-core/test/fraggle-rock/gather/runner-helpers-test.js @@ -7,6 +7,7 @@ const helpers = require('../../../fraggle-rock/gather/runner-helpers.js'); const Gatherer = require('../../../fraggle-rock/gather/base-gatherer.js'); +const {defaultSettings} = require('../../../config/constants.js'); const {createMockDriver, createMockGathererInstance} = require('./mock-driver.js'); /* eslint-env jest */ @@ -130,6 +131,7 @@ describe('collectPhaseArtifacts', () => { phase, gatherMode: /** @type {any} */ (gatherMode), computedCache: new Map(), + settings: defaultSettings, }); expect(artifactState[phase]).toEqual({ Timespan: expect.any(Promise), @@ -152,6 +154,7 @@ describe('collectPhaseArtifacts', () => { gatherMode: 'navigation', phase: 'getArtifact', computedCache: new Map(), + settings: defaultSettings, }); expect(await artifactState.getArtifact.Snapshot).toEqual({type: 'snapshot'}); expect(await artifactState.getArtifact.Timespan).toEqual({type: 'timespan'}); @@ -173,6 +176,7 @@ describe('collectPhaseArtifacts', () => { gatherMode: 'navigation', phase: 'getArtifact', computedCache: new Map(), + settings: defaultSettings, }); expect(artifactState.getArtifact).toEqual({ Dependency: expect.any(Promise), @@ -204,6 +208,7 @@ describe('collectPhaseArtifacts', () => { gatherMode: 'navigation', phase: 'getArtifact', computedCache: new Map(), + settings: defaultSettings, }); expect(artifactState.getArtifact).toEqual({ Snapshot: expect.any(Promise), diff --git a/lighthouse-core/test/gather/gatherers/css-usage-test.js b/lighthouse-core/test/gather/gatherers/css-usage-test.js index bc2a4f40eb6e..f3a7a54e9b25 100644 --- a/lighthouse-core/test/gather/gatherers/css-usage-test.js +++ b/lighthouse-core/test/gather/gatherers/css-usage-test.js @@ -8,6 +8,7 @@ /* eslint-env jest */ const CSSUsage = require('../../../gather/gatherers/css-usage.js'); +const {defaultSettings} = require('../../../config/constants.js'); const {createMockDriver} = require('../../fraggle-rock/gather/mock-driver.js'); describe('.getArtifact', () => { @@ -38,6 +39,7 @@ describe('.getArtifact', () => { gatherMode: 'snapshot', computedCache: new Map(), dependencies: {}, + settings: defaultSettings, }; const gatherer = new CSSUsage(); const artifact = await gatherer.getArtifact(context); @@ -92,6 +94,7 @@ describe('.getArtifact', () => { gatherMode: 'snapshot', computedCache: new Map(), dependencies: {}, + settings: defaultSettings, }; const gatherer = new CSSUsage(); const artifact = await gatherer.getArtifact(context); diff --git a/lighthouse-core/test/gather/gatherers/full-page-screenshot-test.js b/lighthouse-core/test/gather/gatherers/full-page-screenshot-test.js index e89a030ae1d0..9c8449f2f8c6 100644 --- a/lighthouse-core/test/gather/gatherers/full-page-screenshot-test.js +++ b/lighthouse-core/test/gather/gatherers/full-page-screenshot-test.js @@ -70,18 +70,14 @@ describe('FullPageScreenshot gatherer', () => { const fpsGatherer = new FullPageScreenshotGatherer(); contentSize = {width: 412, height: 2000}; - const settings = { + mockContext.settings = { formFactor: 'mobile', screenEmulation: { mobile: true, disabled: false, }, }; - const context = { - ...mockContext.asContext(), - dependencies: {Settings: settings}, - }; - const artifact = await fpsGatherer.getArtifact(context); + const artifact = await fpsGatherer.getArtifact(mockContext.asContext()); expect(artifact).toEqual({ screenshot: { @@ -93,44 +89,18 @@ describe('FullPageScreenshot gatherer', () => { }); }); - it('captures a full-page screenshot in legacy mode', async () => { + it('resets the emulation correctly when Lighthouse controls it', async () => { const fpsGatherer = new FullPageScreenshotGatherer(); contentSize = {width: 412, height: 2000}; - - const settings = { + mockContext.settings = { formFactor: 'mobile', screenEmulation: { mobile: true, disabled: false, }, }; - const context = { - ...mockContext.asLegacyContext(), - settings, - }; - const artifact = await fpsGatherer.afterPass(context); - - expect(artifact).toEqual({ - screenshot: { - data: 'data:image/jpeg;base64,abc', - height: 2000, - width: 412, - }, - nodes: {}, - }); - }); - - it('resets the emulation correctly when Lighthouse controls it', async () => { - const fpsGatherer = new FullPageScreenshotGatherer(); - contentSize = {width: 412, height: 2000}; - await fpsGatherer._getArtifact(mockContext.asContext(), { - formFactor: 'mobile', - screenEmulation: { - mobile: true, - disabled: false, - }, - }); + await fpsGatherer.getArtifact(mockContext.asContext()); const expectedArgs = {formFactor: 'mobile', screenEmulation: {disabled: false, mobile: true}}; expect(mocks.emulationMock.emulate).toHaveBeenCalledTimes(1); @@ -144,14 +114,15 @@ describe('FullPageScreenshot gatherer', () => { const fpsGatherer = new FullPageScreenshotGatherer(); contentSize = {width: 500, height: 1500}; screenSize = {width: 500, height: 500, dpr: 2}; - - await fpsGatherer._getArtifact(mockContext.asContext(), { + mockContext.settings = { screenEmulation: { mobile: true, disabled: true, }, formFactor: 'mobile', - }); + }; + + await fpsGatherer.getArtifact(mockContext.asContext()); // Setting up for screenshot. expect(mockContext.driver.defaultSession.sendCommand).toHaveBeenCalledWith( @@ -185,14 +156,15 @@ describe('FullPageScreenshot gatherer', () => { contentSize = {width: 412, height: 100000}; screenSize = {dpr: 1}; - - await fpsGatherer._getArtifact(mockContext.asContext(), { + mockContext.settings = { formFactor: 'mobile', screenEmulation: { mobile: true, disabled: false, }, - }); + }; + + await fpsGatherer.getArtifact(mockContext.asContext()); expect(mockContext.driver.defaultSession.sendCommand).toHaveBeenCalledWith( 'Emulation.setDeviceMetricsOverride', diff --git a/types/artifacts.d.ts b/types/artifacts.d.ts index e0bd2cc78cc5..3a4e4762b767 100644 --- a/types/artifacts.d.ts +++ b/types/artifacts.d.ts @@ -162,8 +162,6 @@ declare global { ResponseCompression: {requestId: string, url: string, mimeType: string, transferSize: number, resourceSize: number, gzipSize?: number}[]; /** Information on fetching and the content of the /robots.txt file. */ RobotsTxt: {status: number|null, content: string|null}; - /** An object containing information about the testing configuration used by Lighthouse. */ - Settings: Config.Settings; /** Version information for all ServiceWorkers active after the first page load. */ ServiceWorker: {versions: Crdp.ServiceWorker.ServiceWorkerVersion[], registrations: Crdp.ServiceWorker.ServiceWorkerRegistration[]}; /** Source maps of scripts executed in the page. */ diff --git a/types/gatherer.d.ts b/types/gatherer.d.ts index 0e6f9c4a8b0a..e6de453bd5a8 100644 --- a/types/gatherer.d.ts +++ b/types/gatherer.d.ts @@ -46,6 +46,7 @@ declare global { computedCache: Map; /** The set of available dependencies requested by the current gatherer. */ dependencies: Pick>; + settings: Config.Settings; } export interface PassContext { From 33261a8dbe82e072d3ea6a8516d679e428fd30fb Mon Sep 17 00:00:00 2001 From: Adam Raine Date: Thu, 27 May 2021 22:46:59 -0400 Subject: [PATCH 5/6] cleanup --- .../test/gather/gatherers/full-page-screenshot-test.js | 5 ++++- types/gatherer.d.ts | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lighthouse-core/test/gather/gatherers/full-page-screenshot-test.js b/lighthouse-core/test/gather/gatherers/full-page-screenshot-test.js index 9c8449f2f8c6..ced41c7d19e4 100644 --- a/lighthouse-core/test/gather/gatherers/full-page-screenshot-test.js +++ b/lighthouse-core/test/gather/gatherers/full-page-screenshot-test.js @@ -26,6 +26,9 @@ let screenshotData; let mockContext = createMockContext(); beforeEach(() => { + contentSize = {width: 100, height: 100}; + screenSize = {dpr: 1}; + screenshotData = []; mockContext = createMockContext(); mockContext.driver.defaultSession.sendCommand.mockImplementation(method => { if (method === 'Page.getLayoutMetrics') { @@ -66,7 +69,7 @@ beforeEach(() => { }); describe('FullPageScreenshot gatherer', () => { - it('captures a full-page screenshot in FR', async () => { + it('captures a full-page screenshot', async () => { const fpsGatherer = new FullPageScreenshotGatherer(); contentSize = {width: 412, height: 2000}; diff --git a/types/gatherer.d.ts b/types/gatherer.d.ts index e6de453bd5a8..7e1a82bdd86f 100644 --- a/types/gatherer.d.ts +++ b/types/gatherer.d.ts @@ -46,6 +46,7 @@ declare global { computedCache: Map; /** The set of available dependencies requested by the current gatherer. */ dependencies: Pick>; + /** The settings used for gathering. */ settings: Config.Settings; } From dbb984898fc7bfbbf94b4ec1ead20b6028c92f27 Mon Sep 17 00:00:00 2001 From: Adam Raine Date: Tue, 1 Jun 2021 11:37:33 -0400 Subject: [PATCH 6/6] rm param --- lighthouse-core/gather/gatherers/full-page-screenshot.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lighthouse-core/gather/gatherers/full-page-screenshot.js b/lighthouse-core/gather/gatherers/full-page-screenshot.js index 50518072744c..1bb9a10114bb 100644 --- a/lighthouse-core/gather/gatherers/full-page-screenshot.js +++ b/lighthouse-core/gather/gatherers/full-page-screenshot.js @@ -43,10 +43,9 @@ class FullPageScreenshot extends FRGatherer { /** * @param {LH.Gatherer.FRTransitionalContext} context - * @param {LH.Config.Settings} settings * @return {Promise} */ - async _takeScreenshot(context, settings) { + async _takeScreenshot(context) { const session = context.driver.defaultSession; const maxScreenshotHeight = await this.getMaxScreenshotHeight(context); const metrics = await session.sendCommand('Page.getLayoutMetrics'); @@ -62,7 +61,7 @@ class FullPageScreenshot extends FRGatherer { await session.sendCommand('Emulation.setDeviceMetricsOverride', { // If we're gathering with mobile screenEmulation on (overlay scrollbars, etc), continue to use that for this screenshot. - mobile: settings.screenEmulation.mobile, + mobile: context.settings.screenEmulation.mobile, height, width, deviceScaleFactor: 1, @@ -147,7 +146,7 @@ class FullPageScreenshot extends FRGatherer { try { return { - screenshot: await this._takeScreenshot(context, settings), + screenshot: await this._takeScreenshot(context), nodes: await this._resolveNodes(context), }; } finally {