Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(lr): add LR presets for desktop and mobile #5886

Merged
merged 8 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lighthouse-core/config/lr-desktop-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @license Copyright 2018 Google Inc. 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';

/** @type {LH.Config.Json} */
const config = {
extends: 'lighthouse:default',
settings: {
disableDeviceEmulation: true,
throttling: {
// Using a "broadband" connection type
// Corresponds to "Dense 4G 25th percentile" in https://docs.google.com/document/d/1Ft1Bnq9-t4jK5egLSOc28IL4TvR-Tt0se_1faTA4KTY/edit#heading=h.bb7nfy2x9e5v
rttMs: 40,
throughputKbps: 10 * 1024,
cpuSlowdownMultiplier: 1,
},
},
};

module.exports = config;
14 changes: 14 additions & 0 deletions lighthouse-core/config/lr-mobile-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @license Copyright 2018 Google Inc. 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';

/** @type {LH.Config.Json} */
const config = {
extends: 'lighthouse:default',
settings: {},
};

module.exports = config;
26 changes: 21 additions & 5 deletions lighthouse-extension/app/src/lighthouse-ext-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ const ExtensionProtocol = require('../../../lighthouse-core/gather/connections/e
const log = require('lighthouse-logger');
const assetSaver = require('../../../lighthouse-core/lib/asset-saver.js');

/** @type {Record<'mobile'|'desktop', LH.Config.Json>} */
const LR_PRESETS = {
mobile: require('../../../lighthouse-core/config/lr-mobile-config'),
desktop: require('../../../lighthouse-core/config/lr-desktop-config'),
};

/** @typedef {import('../../../lighthouse-core/gather/connections/connection.js')} Connection */

const STORAGE_KEY = 'lighthouse_audits';
Expand Down Expand Up @@ -85,13 +91,23 @@ async function runLighthouseInExtension(flags, categoryIDs) {
* @param {Connection} connection
* @param {string} url
* @param {LH.Flags} flags Lighthouse flags, including `output`
* @param {Array<string>} categoryIDs Name values of categories to include.
* @param {{logAssets: boolean}} lrOpts Options coming from Lightrider
* @param {{lrDevice?: 'desktop'|'mobile', categoryIDs?: Array<string>, logAssets: boolean}} lrOpts Options coming from Lightrider
* @return {Promise<string|Array<string>|void>}
*/
async function runLighthouseAsInCLI(connection, url, flags, categoryIDs, {logAssets}) {
async function runLighthouseInLR(connection, url, flags, {lrDevice, categoryIDs, logAssets}) {
// Override default device to be desktop, since LR default device has viewport 1x1.
connection.sendCommand('Emulation.setDeviceMetricsOverride',
{width: 800, height: 600, deviceScaleFactor: 0, mobile: false});

// disableStorageReset because it causes render server hang
flags.disableStorageReset = true;
flags.logLevel = flags.logLevel || 'info';
const config = background.getDefaultConfigForCategories(categoryIDs);
const config = lrDevice === 'desktop' ? LR_PRESETS.desktop : LR_PRESETS.mobile;
if (categoryIDs) {
config.settings = config.settings || {};
config.settings.onlyCategories = categoryIDs;
}

const results = await lighthouse(url, flags, config, connection);
if (!results) return;

Expand Down Expand Up @@ -217,7 +233,7 @@ if (typeof module !== 'undefined' && module.exports) {
// @ts-ignore
window.runLighthouseInExtension = runLighthouseInExtension;
// @ts-ignore
window.runLighthouseAsInCLI = runLighthouseAsInCLI;
window.runLighthouseInLR = runLighthouseInLR;
// @ts-ignore
window.getDefaultCategories = background.getDefaultCategories;
// @ts-ignore
Expand Down