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

report(devtools): fix wrong emulation string in meta block #14672

Merged
merged 4 commits into from
Jan 13, 2023
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
16 changes: 13 additions & 3 deletions core/util.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,24 @@ class Util {
summary = cpuThrottling = networkThrottling = Util.i18n.strings.runtimeUnknown;
}

// devtools-entry.js always sets `screenEmulation.disabled` when using mobile emulation,
// because we handle the emulation outside of Lighthouse. Since the screen truly is emulated
// as a mobile device, ignore `.disabled` in devtools and just check the form factor
const isScreenEmulationDisabled = settings.channel === 'devtools' ?
false :
settings.screenEmulation.disabled;
const isScreenEmulationMobile = settings.channel === 'devtools' ?
settings.formFactor === 'mobile' :
settings.screenEmulation.mobile;

let deviceEmulation = Util.i18n.strings.runtimeMobileEmulation;
if (settings.screenEmulation.disabled) {
if (isScreenEmulationDisabled) {
deviceEmulation = Util.i18n.strings.runtimeNoEmulation;
} else if (!settings.screenEmulation.mobile) {
} else if (!isScreenEmulationMobile) {
deviceEmulation = Util.i18n.strings.runtimeDesktopEmulation;
}

const screenEmulation = settings.screenEmulation.disabled ?
const screenEmulation = isScreenEmulationDisabled ?
undefined :
// eslint-disable-next-line max-len
`${settings.screenEmulation.width}x${settings.screenEmulation.height}, DPR ${settings.screenEmulation.deviceScaleFactor}`;
Expand Down
16 changes: 13 additions & 3 deletions report/renderer/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,24 @@ class Util {
summary = cpuThrottling = networkThrottling = Util.i18n.strings.runtimeUnknown;
}

// devtools-entry.js always sets `screenEmulation.disabled` when using mobile emulation,
// because we handle the emulation outside of Lighthouse. Since the screen truly is emulated
// as a mobile device, ignore `.disabled` in devtools and just check the form factor
const isScreenEmulationDisabled = settings.channel === 'devtools' ?
false :
settings.screenEmulation.disabled;
const isScreenEmulationMobile = settings.channel === 'devtools' ?
settings.formFactor === 'mobile' :
settings.screenEmulation.mobile;

let deviceEmulation = Util.i18n.strings.runtimeMobileEmulation;
if (settings.screenEmulation.disabled) {
if (isScreenEmulationDisabled) {
deviceEmulation = Util.i18n.strings.runtimeNoEmulation;
} else if (!settings.screenEmulation.mobile) {
} else if (!isScreenEmulationMobile) {
deviceEmulation = Util.i18n.strings.runtimeDesktopEmulation;
}

const screenEmulation = settings.screenEmulation.disabled ?
const screenEmulation = isScreenEmulationDisabled ?
undefined :
// eslint-disable-next-line max-len
`${settings.screenEmulation.width}x${settings.screenEmulation.height}, DPR ${settings.screenEmulation.deviceScaleFactor}`;
Expand Down
2 changes: 2 additions & 0 deletions report/test/renderer/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ describe('util helpers', () => {
/* eslint-disable max-len */
assert.equal(get({formFactor: 'mobile', screenEmulation: {disabled: false, mobile: true}}), 'Emulated Moto G4');
assert.equal(get({formFactor: 'mobile', screenEmulation: {disabled: true, mobile: true}}), 'No emulation');
assert.equal(get({formFactor: 'mobile', screenEmulation: {disabled: true, mobile: true}, channel: 'devtools'}), 'Emulated Moto G4');
assert.equal(get({formFactor: 'desktop', screenEmulation: {disabled: false, mobile: false}}), 'Emulated Desktop');
assert.equal(get({formFactor: 'desktop', screenEmulation: {disabled: true, mobile: false}}), 'No emulation');
assert.equal(get({formFactor: 'desktop', screenEmulation: {disabled: true, mobile: true}, channel: 'devtools'}), 'Emulated Desktop');
/* eslint-enable max-len */
});

Expand Down