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(emulation): refactor emulation settings & CLI flags #11779

Merged
merged 67 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
2663a9c
batch rename emulatedFormFactor to formFactor
paulirish Dec 3, 2020
565ee83
throw if eFF or internalDDSE are set
paulirish Dec 3, 2020
bd19dd8
mostly remove internalDisableDeviceScreenEmulation
paulirish Dec 3, 2020
fac4b46
remove TestedAsMobileDevice
paulirish Dec 3, 2020
40e2617
add disableScreenEmulation
paulirish Dec 3, 2020
1e97bf8
add screenEmulation and emulatedUserAgent to config
paulirish Dec 3, 2020
8f38c6a
lint. plenty of TS errors awaiting me. :)
paulirish Dec 3, 2020
2716b92
move disableScreenEmulation to screenEmulation===false
paulirish Dec 5, 2020
f413348
add emulatedUserAgent === false
paulirish Dec 5, 2020
ce850ef
artifacts + samplejson
paulirish Dec 5, 2020
c7c2d9c
tests. fixing up to match. emulation-test got the most significant
paulirish Dec 6, 2020
4a61dbf
add desktop preset
paulirish Dec 6, 2020
36b99a3
add docs
paulirish Dec 7, 2020
2f378ff
cli flags
paulirish Dec 7, 2020
ce9b4f8
assert valid flags and settings
paulirish Dec 7, 2020
3e5fe75
toe Pick
paulirish Dec 8, 2020
bab1c15
undefined default for a boolean yargs
paulirish Dec 8, 2020
f3c6d35
devtools-entry tweak. webtests will fail until internalDisableDeviceS…
paulirish Dec 8, 2020
673428e
Merge branch 'master' into emulation-flags-refactor
paulirish Dec 8, 2020
04f623c
fix/update proto
paulirish Dec 8, 2020
055f99f
Update docs/emulation.md
paulirish Dec 8, 2020
2f4bc4c
Update docs/emulation.md
paulirish Dec 8, 2020
667368b
Update docs/emulation.md
paulirish Dec 8, 2020
c416277
small initial feedback
paulirish Dec 8, 2020
ed863bd
Apply brendan's suggestions from code review
paulirish Dec 9, 2020
314f9e9
tweaked types based on feedback
paulirish Dec 11, 2020
163c1d5
propagating new type changes
paulirish Dec 14, 2020
f3d8daf
tests
paulirish Dec 14, 2020
0640d22
adjustments but tests not passing
paulirish Dec 14, 2020
7bb30f4
Merge remote-tracking branch 'origin/master' into emulation-flags-ref…
paulirish Dec 14, 2020
c7e0f79
partial to resolve dt-entry use
paulirish Dec 14, 2020
d612f15
feedback on test methods
paulirish Dec 14, 2020
3200813
types.
paulirish Dec 14, 2020
79af0a7
cli test snapshot
paulirish Dec 14, 2020
40698f5
feedback from review
paulirish Dec 14, 2020
a2ad362
fix tests
paulirish Dec 14, 2020
9a230dd
Merge branch 'master' into emulation-flags-refactor (includes conflict)
paulirish Dec 15, 2020
9242bf7
resolve cli conflicts, still need to readd cli flag changes
paulirish Dec 15, 2020
9019612
restored cli flag changes
paulirish Dec 15, 2020
4c91515
desktop preset needs help :/
paulirish Dec 15, 2020
391a7b0
add failing test for desktop vs config
paulirish Dec 15, 2020
1a91693
formFactor CLI no longer gets default
paulirish Dec 15, 2020
9adf303
update readme CLI flags
paulirish Dec 15, 2020
55247d9
fix screenEmulation cli flags type
paulirish Dec 15, 2020
584277c
lint
paulirish Dec 15, 2020
dd4acce
devtools compat and remapping
paulirish Dec 15, 2020
702fece
Update lighthouse-cli/cli-flags.js
paulirish Dec 15, 2020
78a75b3
Merge remote-tracking branch 'origin/master' into emulation-flags-ref…
paulirish Dec 15, 2020
c23a4ea
type capitalization
paulirish Dec 15, 2020
af2946d
devtools emulate-run: assert more emulation items
paulirish Dec 15, 2020
cec1586
minor
paulirish Dec 15, 2020
4a84840
Update lighthouse-core/config/config.js
paulirish Dec 15, 2020
a84d0b8
Update docs/emulation.md
paulirish Dec 15, 2020
39d80f8
ts-expect-error
paulirish Dec 15, 2020
d833938
Update docs/emulation.md
paulirish Dec 15, 2020
2e8b139
typo fix from patrick ( and 2 other minor wording tweaks)
paulirish Dec 15, 2020
1c3731e
object arg format for all existing and new uses of getFakeContext()
paulirish Dec 15, 2020
8b27252
Apply suggestions from code review
paulirish Dec 15, 2020
3caee82
Apply suggestions from code review
paulirish Dec 15, 2020
f31a89d
screenshot smoketest fix
paulirish Dec 15, 2020
05917d1
semicolon-gate
paulirish Dec 15, 2020
31a7b55
drop todo on formfactor
paulirish Dec 15, 2020
09fb558
feedback from brendan. emuUA cast still outstanding
paulirish Dec 16, 2020
77d98c7
readme whitespace yay
paulirish Dec 16, 2020
7a0e1b9
bespoke emuUA initialization comment
paulirish Dec 16, 2020
c4a19c6
emulatedUserAgent tests, authored by Brendan Kenny
paulirish Dec 16, 2020
58179b0
tests arent typed
paulirish Dec 16, 2020
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
8 changes: 6 additions & 2 deletions clients/devtools-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const lighthouse = require('../lighthouse-core/index.js');
const RawProtocol = require('../lighthouse-core/gather/connections/raw.js');
const log = require('lighthouse-logger');
const {registerLocaleData, lookupLocale} = require('../lighthouse-core/lib/i18n/i18n.js');
const desktopDense4G = require('../lighthouse-core/config/constants.js').throttling.desktopDense4G;
const constants = require('../lighthouse-core/config/constants.js');

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

Expand All @@ -28,9 +28,13 @@ function createConfig(categoryIDs, device) {
/** @type {LH.SharedFlagsSettings} */
const settings = {
onlyCategories: categoryIDs,
// DevTools handles all the emulation
screenEmulation: {disabled: true},
brendankenny marked this conversation as resolved.
Show resolved Hide resolved
};
if (device === 'desktop') {
settings.throttling = desktopDense4G;
settings.throttling = constants.throttling.desktopDense4G;
settings.emulatedUserAgent = constants.userAgents.desktop;
settings.formFactor = 'desktop';
}

return {
Expand Down
4 changes: 2 additions & 2 deletions clients/test/lightrider-entry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('lightrider-entry', () => {
const lrDevice = 'desktop';
await lhBackground.runLighthouseInLR(mockConnection, url, {}, {lrDevice});
const config = runStub.mock.calls[0][1].config;
assert.equal(config.settings.emulatedFormFactor, 'desktop');
assert.equal(config.settings.formFactor, 'desktop');

runStub.mockRestore();
});
Expand All @@ -94,7 +94,7 @@ describe('lightrider-entry', () => {
const lrDevice = 'mobile';
await lhBackground.runLighthouseInLR(mockConnection, url, {}, {lrDevice});
const config = runStub.mock.calls[0][1].config;
assert.equal(config.settings.emulatedFormFactor, 'mobile');
assert.equal(config.settings.formFactor, 'mobile');

runStub.mockRestore();
});
Expand Down
32 changes: 32 additions & 0 deletions docs/emulation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

# Emulation in Lighthouse

In Lighthouse, "Emulation" refers to the screen/viewport emulation and UserAgent string spoofing.
["Throttling"](./throttling.md) covers the similar topics around network and CPU throttling/simulation.

With the default configuration, Lighthouse emulates a mobile device. There's [a `desktop` configuration](../lighthouse-core/config/desktop-config.js), available to CLI users with `--preset=desktop`, which applies a consistent desktop environment and scoring calibration. This is recommended as a replacement for `--emulation-form-factor=desktop`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
With the default configuration, Lighthouse emulates a mobile device. There's [a `desktop` configuration](../lighthouse-core/config/desktop-config.js), available to CLI users with `--preset=desktop`, which applies a consistent desktop environment and scoring calibration. This is recommended as a replacement for `--emulation-form-factor=desktop`.
With the default configuration, Lighthouse emulates a mobile device. There's [a `desktop` configuration](../lighthouse-core/config/desktop-config.js), available to CLI users with `--preset=desktop`, which applies a consistent desktop environment and scoring calibration. This is recommended as a replacement for `--form-factor=desktop`.

Or if this was referring to the v6 flags then --emulated-form-factor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah typo. i meant to refer to refer to that (i added this to docs excepting we'll get people who used -eff=desktop without problems before and want the quick answer)

thx


### Advanced emulation setups

Some products use Lighthouse in scenarios where emulation is applied outside of Lighthouse (eg by Puppeteer) or running against Chrome on real mobile devices.
paulirish marked this conversation as resolved.
Show resolved Hide resolved

You must always set `formFactor`. It doesn't control emulation, but it determines how Lighthouse should interpret the run in regards to scoring performance metrics and skipping mobile-only tests in desktop.

You can choose how `screenEmulation` is applied. It can accept an object of `{width: number, height: number, deviceScaleRatio: number, mobile: boolean, disabled: false}` to apply that screen emulation or an object of `{disabled: true}` if Lighthouse should avoid applying screen emulation. It's typically set to disabled if either emulation is applied outside of Lighthouse, or it's being run on a mobile device. The `mobile` boolean applies overlay scrollbars and a few other mobile-specific screen emulation characteristics.

You can choose how to handle userAgent emulation. The `emulatedUserAgent` property accepts either a `string` to apply the provided userAgent or a `boolean` -- `true` if the default UA spoofing should be applied (default) or `false` if no UA spoofing should be applied. Typically `false` is used if UA spoofing is applied outside of Lighthouse or on a mobile device. You can also redundantly apply userAgent emulation with no risk.

If you're using Lighthouse on a mobile device, you want to set `--screenEmulation.disabled` and `--throttling.cpuSlowdownMultiplier=1`. (`--formFactor=mobile` is the default already).

### Changes made in v7

In Lighthouse v7, most of the configuration regarding emulation changed to be more intuitive and clear. The [tracking issue](https://github.com/GoogleChrome/lighthouse/issues/10910
) captures additional motivations.

* Removed: The `emulatedFormFactor` property (which determined how emulation is applied).
* Removed: The `TestedAsMobileDevice` artifact. Instead of being inferred, the `formFactor` property is used.
* Removed: The `internalDisableDeviceScreenEmulation` property. It's equivalent to the new `screenEmulation: false`.
paulirish marked this conversation as resolved.
Show resolved Hide resolved
* Added: The `formFactor` property.
* Added: The `screenEmulation` property.
* Added: The `emulatedUserAgent` property.
* (`throttling` and `throttlingMethod` remain unchanged)
3 changes: 1 addition & 2 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ The following artifacts are available for use in the audits of Lighthouse plugin
- `RuntimeExceptions`
- `ScriptElements`
- `Stacks`
- `TestedAsMobileDevice`
- `Timing`
- `URL`
- `ViewportDimensions`
Expand Down Expand Up @@ -371,6 +370,6 @@ Most artifacts will try to represent as truthfully as possible what was observed
- [Field Performance](https://github.com/treosh/lighthouse-plugin-field-performance) - A plugin to gather and display Chrome UX Report field data
- [AMP Plugin](https://github.com/ampproject/amp-toolbox/tree/main/packages/lighthouse-plugin-amp) - Runs pages through the AMP validator.
- [Publisher Ads Audits](https://github.com/googleads/pub-ads-lighthouse-plugin) - a well-written, but complex, plugin
- [Green Web Foundation](https://github.com/thegreenwebfoundation/lighthouse-plugin-greenhouse) - A plugin to see which domains run on renewable power.
- [Green Web Foundation](https://github.com/thegreenwebfoundation/lighthouse-plugin-greenhouse) - A plugin to see which domains run on renewable power.
- [requests-content-md5](https://www.npmjs.com/package/lighthouse-plugin-md5) - Generates MD5 hashes from the content of network requests..

4 changes: 2 additions & 2 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Alternatively, you can instruct Chrome to ignore the invalid certificate by addi

Lighthouse can run against a real mobile device. You can follow the [Remote Debugging on Android (Legacy Workflow)](https://developer.chrome.com/devtools/docs/remote-debugging-legacy) up through step 3.3, but the TL;DR is install & run adb, enable USB debugging, then port forward 9222 from the device to the machine with Lighthouse.

You'll likely want to use the CLI flags `--emulated-form-factor=none --throttling.cpuSlowdownMultiplier=1` to disable any additional emulation.
You'll likely want to use the CLI flags `--screenEmulation.disabled --throttling.cpuSlowdownMultiplier=1` to disable any additional emulation.

```sh
$ adb kill-server
Expand All @@ -128,7 +128,7 @@ $ adb devices -l

$ adb forward tcp:9222 localabstract:chrome_devtools_remote

$ lighthouse --port=9222 --emulated-form-factor=none --throttling.cpuSlowdownMultiplier=1 https://example.com
$ lighthouse --port=9222 --screenEmulation.disabled --throttling.cpuSlowdownMultiplier=1 https://example.com
```

## Lighthouse as trace processor
Expand Down
2 changes: 1 addition & 1 deletion docs/understanding-results.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ An object containing information about the configuration used by Lighthouse.
},
"gatherMode": false,
"disableStorageReset": false,
"emulatedFormFactor": "mobile",
"formFactor": "mobile",
"blockedUrlPatterns": null,
"additionalTraceCategories": null,
"extraHeaders": null,
Expand Down
6 changes: 0 additions & 6 deletions lighthouse-cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ async function begin() {
cliFlags.outputPath = 'stdout';
}

// @ts-expect-error - deprecation message for removed disableDeviceEmulation; can remove warning in v6.
if (cliFlags.disableDeviceEmulation) {
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
log.warn('config', 'The "--disable-device-emulation" has been removed in v5.' +
' Please use "--emulated-form-factor=none" instead.');
}

if (cliFlags.precomputedLanternDataPath) {
const lanternDataStr = fs.readFileSync(cliFlags.precomputedLanternDataPath, 'utf8');
/** @type {LH.PrecomputedLanternData} */
Expand Down
62 changes: 56 additions & 6 deletions lighthouse-cli/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getFlags(manualArgv) {
'lighthouse <url> --output=json --output-path=./report.json --save-assets',
'Save trace, screenshots, and named JSON report.')
.example(
'lighthouse <url> --emulated-form-factor=none --throttling-method=provided',
'lighthouse <url> --screenEmulation.disabled --throttling-method=provided --no-emulatedUserAgent',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely looks weird interspersing camelCase and kebab-case. Agreed that --screen-emulation.disabled also looks weird, but for non-dot ones --no-emulatedUserAgent is kind of confusing...

'Disable device emulation and all throttling')
.example(
'lighthouse <url> --chrome-flags="--window-size=412,660"',
Expand Down Expand Up @@ -137,9 +137,17 @@ function getFlags(manualArgv) {
default: 'localhost',
describe: 'The hostname to use for the debugging protocol.',
},
'emulated-form-factor': {
'form-factor': {
type: 'string',
describe: 'Controls the emulated device form factor (mobile vs. desktop) if not disabled',
describe: 'Determines how performance metrics are scored and if mobile-only audits are skipped. For desktop, --preset=desktop instead.',
},
'screenEmulation': {
describe: 'Sets screen emulation parameters. See also --preset. Use --screenEmulation.disabled to disable. Otherwise set these 4 parameters individually: --screenEmulation.mobile --screenEmulation.width=360 --screenEmulation.height=640 --screenEmulation.deviceScaleFactor=2',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

purposefully don't want to break these up like throttling?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct. I don't wanna grow --help even more.

coerce: coerceScreenEmulation,
},
'emulatedUserAgent': {
type: 'string',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that doing it this way means --no-emulated-user-agent works (it gives false), but

  • --emulated-user-agent gives ''
  • --emulated-user-agent false gives (the string) 'false'.

better to use coerce: coerceOptionalStringBoolean, like audit-mode and gather-mode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya good call.

describe: 'Sets useragent emulation',
},
'max-wait-for-load': {
type: 'number',
Expand Down Expand Up @@ -185,7 +193,7 @@ function getFlags(manualArgv) {
})
.group([
'save-assets', 'list-all-audits', 'list-trace-categories', 'print-config', 'additional-trace-categories',
'config-path', 'preset', 'chrome-flags', 'port', 'hostname', 'emulated-form-factor',
'config-path', 'preset', 'chrome-flags', 'port', 'hostname', 'form-factor', 'screenEmulation', 'emulatedUserAgent',
'max-wait-for-load', 'enable-error-reporting', 'gather-mode', 'audit-mode',
'only-audits', 'only-categories', 'skip-audits', 'budget-path',
], 'Configuration:')
Expand Down Expand Up @@ -278,9 +286,9 @@ function getFlags(manualArgv) {
})

// Choices added outside of `options()` and cast so tsc picks them up.
.choices('emulated-form-factor', /** @type {['mobile', 'desktop', 'none']} */ (['mobile', 'desktop', 'none']))
.choices('form-factor', /** @type {['mobile', 'desktop']} */ (['mobile', 'desktop']))
.choices('throttling-method', /** @type {['devtools', 'provided', 'simulate']} */ (['devtools', 'provided', 'simulate']))
.choices('preset', /** @type {['perf', 'experimental']} */ (['perf', 'experimental']))
.choices('preset', /** @type {['perf', 'experimental', 'desktop']} */ (['perf', 'experimental', 'desktop']))

.check(argv => {
// Lighthouse doesn't need a URL if...
Expand Down Expand Up @@ -418,6 +426,48 @@ function coerceThrottling(value) {
return throttlingSettings;
}

/**
* Take yarg's unchecked object value and ensure it is a proper LH.screenEmulationSettings.
* @param {unknown} value
* @return {LH.ScreenEmulationSettings}
paulirish marked this conversation as resolved.
Show resolved Hide resolved
*/
function coerceScreenEmulation(value) {
if (!isObjectOfUnknownValues(value)) {
throw new Error(`Invalid value: Argument 'screenEmulation' must be an object, specified per-property ('screenEmulation.width', 'screenEmulation.deviceScaleFactor', etc)`);
}

/** @type {Array<keyof LH.ScreenEmulationSettings>} */
const keys = ['width', 'height', 'deviceScaleFactor', 'mobile', 'disabled'];
/** @type {LH.ScreenEmulationSettings} */
paulirish marked this conversation as resolved.
Show resolved Hide resolved
const screenEmulationSettings = {};

for (const key of keys) {
const possibleSetting = value[key];
switch (key) {
case 'width':
case 'height':
case 'deviceScaleFactor':
if (possibleSetting !== undefined && typeof possibleSetting !== 'number') {
throw new Error(`Invalid value: 'screenEmulation.${key}' must be a number`);
}
screenEmulationSettings[key] = possibleSetting;

break;
case 'mobile':
case 'disabled':
if (possibleSetting !== undefined && typeof possibleSetting !== 'boolean') {
throw new Error(`Invalid value: 'screenEmulation.${key}' must be a boolean`);
}
screenEmulationSettings[key] = possibleSetting;
break;
default:
throw new Error(`Unrecognized screenEmulation option: ${key}`);
}
}

return screenEmulationSettings;
}

module.exports = {
getFlags,
};
22 changes: 18 additions & 4 deletions lighthouse-cli/test/cli/__snapshots__/index-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1461,10 +1461,10 @@ Object {
"budgets": null,
"channel": "cli",
"disableStorageReset": false,
"emulatedFormFactor": "mobile",
"emulatedUserAgent": "Mozilla/5.0 (Linux; Android 7.0; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4143.7 Mobile Safari/537.36 Chrome-Lighthouse",
"extraHeaders": null,
"formFactor": "mobile",
"gatherMode": false,
"internalDisableDeviceScreenEmulation": false,
"locale": "en-US",
"maxWaitForFcp": 30000,
"maxWaitForLoad": 45000,
Expand All @@ -1474,6 +1474,13 @@ Object {
"html",
],
"precomputedLanternData": null,
"screenEmulation": Object {
"deviceScaleFactor": 2.625,
"disabled": false,
"height": 640,
"mobile": true,
"width": 360,
},
"skipAudits": null,
"throttling": Object {
"cpuSlowdownMultiplier": 4,
Expand Down Expand Up @@ -1607,10 +1614,10 @@ Object {
"budgets": null,
"channel": "cli",
"disableStorageReset": false,
"emulatedFormFactor": "mobile",
"emulatedUserAgent": "Mozilla/5.0 (Linux; Android 7.0; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4143.7 Mobile Safari/537.36 Chrome-Lighthouse",
"extraHeaders": null,
"formFactor": "mobile",
"gatherMode": false,
"internalDisableDeviceScreenEmulation": false,
"locale": "en-US",
"maxWaitForFcp": 30000,
"maxWaitForLoad": 45000,
Expand All @@ -1622,6 +1629,13 @@ Object {
"json",
],
"precomputedLanternData": null,
"screenEmulation": Object {
"deviceScaleFactor": 2.625,
"disabled": false,
"height": 640,
"mobile": true,
"width": 360,
},
"skipAudits": null,
"throttling": Object {
"cpuSlowdownMultiplier": 4,
Expand Down
39 changes: 39 additions & 0 deletions lighthouse-cli/test/cli/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,43 @@ describe('CLI Tests', function() {
expect(config).toMatchSnapshot();
});
});

describe('preset', () => {
it('desktop should set appropriate config', () => {
const ret = spawnSync('node', [indexPath, '--print-config', '--preset=desktop'], {
encoding: 'utf8',
});

const config = JSON.parse(ret.stdout);
const {emulatedUserAgent, formFactor, screenEmulation, throttling, throttlingMethod} =
config.settings;
const emulationSettings =
{emulatedUserAgent, formFactor, screenEmulation, throttling, throttlingMethod};

/* eslint-disable max-len */
expect(emulationSettings).toMatchInlineSnapshot(`
Object {
"emulatedUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4143.7 Safari/537.36 Chrome-Lighthouse",
"formFactor": "desktop",
"screenEmulation": Object {
"deviceScaleFactor": 1,
"disabled": false,
"height": 940,
"mobile": false,
"width": 1350,
},
"throttling": Object {
"cpuSlowdownMultiplier": 1,
"downloadThroughputKbps": 0,
"requestLatencyMs": 0,
"rttMs": 40,
"throughputKbps": 10240,
"uploadThroughputKbps": 0,
},
"throttlingMethod": "simulate",
}
`);
/* eslint-enable max-len */
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const expectations = [
{
artifacts: {
HostFormFactor: 'desktop',
TestedAsMobileDevice: true,
Stacks: [{
id: 'jquery',
}, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
module.exports = {
extends: 'lighthouse:default',
settings: {
emulatedFormFactor: 'desktop',
formFactor: 'desktop',
},
};
8 changes: 4 additions & 4 deletions lighthouse-core/audits/content-width.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ class ContentWidth extends Audit {
title: str_(UIStrings.title),
failureTitle: str_(UIStrings.failureTitle),
description: str_(UIStrings.description),
requiredArtifacts: ['ViewportDimensions', 'TestedAsMobileDevice'],
requiredArtifacts: ['ViewportDimensions'],
};
}

/**
* @param {LH.Artifacts} artifacts
* @param {LH.Audit.Context} context
* @return {LH.Audit.Product}
*/
static audit(artifacts) {
const IsMobile = artifacts.TestedAsMobileDevice;
static audit(artifacts, context) {
const viewportWidth = artifacts.ViewportDimensions.innerWidth;
const windowWidth = artifacts.ViewportDimensions.outerWidth;
const widthsMatch = viewportWidth === windowWidth;

if (!IsMobile) {
if (context.settings.formFactor === 'desktop') {
return {
score: 1,
notApplicable: true,
Expand Down
5 changes: 2 additions & 3 deletions lighthouse-core/audits/metrics/first-contentful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FirstContentfulPaint extends Audit {
title: str_(i18n.UIStrings.firstContentfulPaintMetric),
description: str_(UIStrings.description),
scoreDisplayMode: Audit.SCORING_MODES.NUMERIC,
requiredArtifacts: ['traces', 'devtoolsLogs', 'TestedAsMobileDevice'],
requiredArtifacts: ['traces', 'devtoolsLogs'],
};
}

Expand Down Expand Up @@ -65,8 +65,7 @@ class FirstContentfulPaint extends Audit {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const metricComputationData = {trace, devtoolsLog, settings: context.settings};
const metricResult = await ComputedFcp.request(metricComputationData, context);
const isDesktop = artifacts.TestedAsMobileDevice === false;
const options = isDesktop ? context.options.desktop : context.options.mobile;
const options = context.options[context.settings.formFactor];

return {
score: Audit.computeLogNormalScore(
Expand Down
Loading