-
Notifications
You must be signed in to change notification settings - Fork 9.6k
core: add settings.internalDisableDeviceScreenEmulation #9377
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
Conversation
|
|
patrickhulce
left a comment
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! though some questions around the edge cases
| const IsMobileHost = hostUserAgent.includes('Android') || hostUserAgent.includes('Mobile'); | ||
| // IsMobilePage indicates whether the page is mobile (with any pre-applied mobile emulation or not) | ||
| // In DevTools, emulation is applied before Lighthouse starts (to deal with viewport emulation bugs) | ||
| // emulatedFormFactor will be 'none', but it's certainly still TestedAsMobileDevice |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| const IsMobilePage = pageUserAgent.includes('Android') || pageUserAgent.includes('Mobile'); | ||
| const TestedAsMobileDevice = emulatedFormFactor === 'mobile' || | ||
| (emulatedFormFactor !== 'desktop' && IsMobileHost); | ||
| (emulatedFormFactor !== 'desktop' && IsMobileHost) || |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| return Promise.resolve(Object.assign({}, protocolGetVersionResponse, {milestone: 71})); | ||
| }, | ||
| getPageUserAgent() { | ||
| return Promise.resolve(driverGetPageUAResponse); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| expect(results.TestedAsMobileDevice).toBe(false); | ||
| }); | ||
|
|
||
| it('works when running via DevTools with emulation applied outside of LH', async () => { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
|
Reworked this completely. Ready for a fresh look. |
patrickhulce
left a comment
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.
love the parallelism with throttlingMethod 😍 , provided feels exactly like what we want here 👍
🚲 🏠 on the name
viewportEmulationMethod
screenEmulationMethod
formFactorScreenEmulationMethod
emulatedFormFactorScreenOverrideMethod
I think I like deviceScreenEmulationMethod best still, but the only bummer is it's not super obvious on first glance that it's so closely related to the emulatedFormFactor
| const hostUserAgent = (await options.driver.getBrowserVersion()).userAgent; | ||
|
|
||
| const {emulatedFormFactor} = options.settings; | ||
|
|
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| /** | ||
| * | ||
| * @param {Driver} driver | ||
| * @return {Promise<void>} |
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.
could leave a @return {Promise<void>} on the new function FWIW :)
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-core/lib/emulation.js
Outdated
| if (settings.deviceScreenEmulationMethod !== 'provided') { | ||
| promises.push( | ||
| ...[ | ||
| driver.sendCommand('Emulation.setDeviceMetricsOverride', params.metrics), |
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.
do these take that long? I feel like this function would be much easier to read if we just await'd each as they came
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 like it.
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-core/lib/emulation.js
Outdated
| await Promise.all([ | ||
| driver.sendCommand('Emulation.setDeviceMetricsOverride', NEXUS5X_EMULATION_METRICS), | ||
| async function emulate(driver, settings) { | ||
| let params; |
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.
is this falling back to any or is ts smart enough to set this properly without explicit typing?
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.
changed up this and got nice typing for it.
lighthouse-core/lib/emulation.js
Outdated
| ]); | ||
| driver.sendCommand('Network.setUserAgentOverride', {userAgent: params.userAgent}), | ||
| ]; | ||
| if (settings.deviceScreenEmulationMethod !== '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.
should we explicitly check 'devtools' since it should be a default by this point?
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.
it means adding the deviceScreenEmulationMethod prop to a bunch of gather-runner-test tests. but ok! done.
proto/lighthouse-result.proto
Outdated
| // Unknown screen emulation method. This should not be used | ||
| UNKNOWN_SCREEN_EMULATION_METHOD = 0; | ||
|
|
||
| // DevTools mobile/desktop viewport emulation shoudl be applied. |
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.
| // DevTools mobile/desktop viewport emulation shoudl be applied. | |
| // DevTools mobile/desktop viewport emulation should be applied. |
proto/lighthouse-result.proto
Outdated
|
|
||
| // The possible form factors an audit can be run in | ||
| enum DeviceScreenEmulationMethod { | ||
| // Unknown screen emulation method. This should not be used |
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.
| // Unknown screen emulation method. This should not be used | |
| // Unknown screen emulation method. This should not be used. |
| const options = {requestedUrl, driver, settings: config.settings}; | ||
|
|
||
| const results = await GatherRunner.run(config.passes, options); | ||
| expect(results.TestedAsMobileDevice).toBe(true); |
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.
this test feels a tad hollow when the TestedAsMobileDevice is based on the mocked result of getBrowserVersion which is not affected by our deviceScreenEmulationMethod here :)
another case for some separate emulation-test tests
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.
fair.
new emulation-test added.
| endTrace: asyncFunc, | ||
| endDevtoolsLog: () => [], | ||
| getBrowserVersion: async () => ({userAgent: ''}), | ||
| getPageUserAgent: async () => '', |
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.
not needed anymore
patrickhulce
left a comment
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.
lookin' great! CLI snapshots need an update for travis.
any thought to the naming bikeshed?
| // UA emulation, however, is lost in the protocol handover from devtools frontend to the audits_worker. So it's always applied. | ||
|
|
||
| // Network.enable must be called for UA overriding to work | ||
| await driver.sendCommand('Network.enable'); |
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.
beautiful ❤️
| 'use strict'; | ||
|
|
||
| const emulation = require('../../lib/emulation.js'); | ||
| const {getMockedEmulationDriver} = require('../gather/gather-runner-test.js'); |
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.
this is within the scope to refactor when the other mock test utils lands, right?
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.
oh yeah. i'm dying to do that.
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 that's gonna be great :D always weird to have test files export junk
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
| await emulation.emulate(driver, getSettings('mobile', 'devtools')); | ||
| expect(setUAFn).toBeCalled(); | ||
| expect(deviceMetricsFn).toBeCalled(); | ||
| expect(getFnCallArgs(setUAFn)[0]).toMatchObject({userAgent: emulation.MOBILE_USERAGENT}); |
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 just get this first argument if it's going to exist? all the usages seem to use it that way.
setUAFn.mock.calls[0][0] is actually 1 fewer character than getFnCallArgs(setUAFn)[0] too btw ;)
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.
sure wfm.
| }); | ||
|
|
||
| it('handles: emulatedFormFactor: mobile / deviceScreenEmulationMethod: devtools', async () => { | ||
| await emulation.emulate(driver, getSettings('mobile', 'devtools')); |
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.
FWIW, I've come to deeply regret all the helper creator functions I made like this in the past and the below doesn't seem so bad 🤷♂
await emulation.emulate(driver, {
emulatedFormFactor: 'mobile',
deviceScreenEmulationMethod: 'devtools',
});:)
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.
aiight
proto/lighthouse-result.proto
Outdated
| string channel = 4; | ||
|
|
||
| // The possible form factors an audit can be run in | ||
| enum DeviceScreenEmulationMethod { |
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.
Is this really necessary in proto? LR will always use one option? Similar to throttling settings is always simulated? We elide much of config for this reason iirc.
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.
nah. we can leave out of the proto for now. i forgot that we only did a subset.
okay i can roll with these ones. They're all decent.
|
exterkamp
left a comment
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 proto 💯
|
This is a blocker for 5.2 (any roll to DT w/o this will be broken). |
all sorted. |
|
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
that's convincing
FWIW, this use case doesn't exist anymore, so w/e about it :)
I don't believe this :P but more seriously, I don't like that adding a is |
eh, I'm not entirely sure how to feel On the one hand, it is equivalent and we're replicating bits with no new information in them. We're down to three LH clients again and it's silly to pretend we support every possible permutation of our options when actually (as you point out), we have some pretty strict requirements of redundancies between them. Better to just specifically configure things for each client. On the other hand, So I guess my vote is actually |
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
WFM! thanks |
Lighthouse master has breaking pre-6.0 changes, so we are cherry-picking a few things on top of 5.6.0. Cherry-picks from master: - d53284cf12e680cbe6a12429cc1c6c4219e7ef43 icu error - 466bd6f79e57950d736de5edfa9642a40f1100fd verbose i18n - 7c16d346593d86b33945d75a996829e1a25b4fed flatten PRs not yet in master, but merged into 5.7.0:: - GoogleChrome/lighthouse#9377 internalDisableDeviceScreenEmulation - GoogleChrome/lighthouse#9936 Bundling pubads Screenshot: https://imgur.com/a/XuHkgWk Bug: 772558 Change-Id: I4a03965ec879119a88faf40dbdca471a9a33e794 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1900472 Commit-Queue: Connor Clark <[email protected]> Commit-Queue: Paul Irish <[email protected]> Reviewed-by: Paul Irish <[email protected]>
Lighthouse master has breaking pre-6.0 changes, so we are cherry-picking a few things on top of 5.6.0. Cherry-picks from master: - d53284cf12e680cbe6a12429cc1c6c4219e7ef43 icu error - 466bd6f79e57950d736de5edfa9642a40f1100fd verbose i18n - 7c16d346593d86b33945d75a996829e1a25b4fed flatten PRs not yet in master, but merged into 5.7.0:: - GoogleChrome/lighthouse#9377 internalDisableDeviceScreenEmulation - GoogleChrome/lighthouse#9936 Bundling pubads Screenshot: https://imgur.com/a/XuHkgWk Bug: 772558 Change-Id: I4a03965ec879119a88faf40dbdca471a9a33e794 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1900472 Commit-Queue: Connor Clark <[email protected]> Commit-Queue: Paul Irish <[email protected]> Reviewed-by: Paul Irish <[email protected]>
|
🎉 |
background: in https://chromium-review.googlesource.com/c/chromium/src/+/1699018 we found that audits panel has been double-emulating. We emulate on the devtools-side before LH starts.. and then due to some bugs in how we rolled out the config change of (disableDeviceEmulation => emulatedFormFactor), we emulated again inside LH.
We end up with odd emulation bugs when the devtools UI remains onscreen while LH runs the emulation show, so we think it's best to let devtools continue emulating. (Plus we get the attractive device frame)
Anyhow, the newTestedAsMobileDeviceartifact doesn't account for this situation, but should.Turns out that during a protocol-handoff the network emulation is lost. So we need LH to (re-)apply network emulation but not the viewport emulation. So I've added a new config setting
SharedFlagsSetting.internalDisableDeviceScreenEmulationto indicate this.DevTools will pass in
emulatedFormFactorof either"mobile"or"desktop"along withinternalDisableDeviceScreenEmulation: true.