-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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: add emulatedFormFactor setting #6098
Conversation
lighthouse-core/lib/emulation.js
Outdated
const DESKTOP_EMULATION_METRICS = { | ||
mobile: false, | ||
screenWidth: 1366, | ||
screenHeight: 768, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulirish it's not 100% clear to me what of these are necessary to zero-out any potential previous emulation 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just trim it down to these:
const DESKTOP_EMULATION_METRICS = {
mobile: false,
width: 1366,
height: 768,
deviceScaleFactor: 1,
};
the rest are reset on the call.
@@ -83,6 +83,7 @@ declare global { | |||
gatherMode?: boolean | string; | |||
disableStorageReset?: boolean; | |||
disableDeviceEmulation?: boolean; | |||
emulatedFormFactor?: 'mobile'|'desktop'|'none'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes me want to add a 'none'
to throttlingMethod that's just an alias of 'provided'
😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes me want to add a
'none'
to throttlingMethod that's just an alias of'provided'
yes pls :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to as it would be confusing if this one has a none but throttling does not.
Maybe add an alias provided here too? 🙄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
We should probably bikeshed for at least a minute on emulated-form-factor
and if it's obvious enough just from the flag name, but I have no strong opinion on it (yet :).
@@ -94,7 +94,9 @@ describe('util helpers', () => { | |||
it('builds device emulation string', () => { | |||
const get = opts => Util.getEmulationDescriptions(opts).deviceEmulation; | |||
assert.equal(get({disableDeviceEmulation: true}), 'No emulation'); | |||
assert.equal(get({disableDeviceEmulation: false}), 'Emulated Nexus 5X'); | |||
assert.equal(get({emulatedFormFactor: 'none'}), 'No emulation'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this include the disableDeviceEmulation: false
-> 'No emulation'
case as well (since no emulatedFormFactor
)? Admittedly Config
won't let you get into this situation due to the emulatedFormFactor
default, but it feels weird to leave out when testing just this file :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done :)
lighthouse-cli/cli-flags.js
Outdated
@@ -70,7 +70,8 @@ function getFlags(manualArgv) { | |||
'blocked-url-patterns': 'Block any network requests to the specified URL patterns', | |||
'disable-storage-reset': | |||
'Disable clearing the browser cache and other storage APIs before a run', | |||
'disable-device-emulation': 'Disable Nexus 5X emulation', | |||
'disable-device-emulation': 'Disable all device form factor emulation', | |||
'emulated-form-factor': 'Controls the emulated device form factor (mobile vs. desktop)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also mention the flag precedence here, like "Controls the emulated device form factor (mobile vs. desktop) if emulation not disabled" or something. It gets weird that none
also disables it, but it isn't too confusing...
(could also add something about Deprecated: use '--emulated-form-factor none'.
to the disable-device-emulation
description)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also update the readme with new --help
output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah good call, done
lighthouse-core/lib/emulation.js
Outdated
const DESKTOP_EMULATION_METRICS = { | ||
mobile: false, | ||
screenWidth: 1366, | ||
screenHeight: 768, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just trim it down to these:
const DESKTOP_EMULATION_METRICS = {
mobile: false,
width: 1366,
height: 768,
deviceScaleFactor: 1,
};
the rest are reset on the call.
lighthouse-core/lib/emulation.js
Outdated
const NEXUS5X_USERAGENT = { | ||
userAgent: 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5 Build/MRA58N) AppleWebKit/537.36' + | ||
'(KHTML, like Gecko) Chrome/66.0.3359.30 Mobile Safari/537.36', | ||
'(KHTML, like Gecko) Chrome/69.0.3497.100 Mobile Safari/537.36', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i usually bump to canary. 71.0.3559.0
here and below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -992,7 +992,11 @@ class Driver { | |||
*/ | |||
async beginEmulation(settings) { | |||
if (!settings.disableDeviceEmulation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add TODO somewhere to remove this flag in a breaking version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 👍
@@ -120,6 +121,7 @@ function getFlags(manualArgv) { | |||
'list-trace-categories', 'view', 'verbose', 'quiet', 'help', | |||
]) | |||
.choices('output', printer.getValidOutputOptions()) | |||
.choices('emulated-form-factor', ['mobile', 'desktop', 'none']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's set the default to mobile here in the CLI too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
Summary
Introduces a new
emulatedFormFactor
enum to settings to eventually replacedisableDeviceEmulation
which is still respected.emulatedFormFactor
defaults tomobile
but can be one ofmobile
,desktop
, ornone
.none
is equivalent to settingdisableDeviceEmulation
totrue
.Related Issues/PRs
closes #6092