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

misc(proto): add screenEmulation to configSettings #14809

Merged
merged 2 commits into from
Feb 21, 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
2 changes: 2 additions & 0 deletions core/lib/proto-preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function processForProto(lhr) {
onlyCategories,
channel,
throttling,
screenEmulation,
throttlingMethod} = reportJson.configSettings;

// @ts-expect-error - intentionally only a subset of settings.
Expand All @@ -44,6 +45,7 @@ function processForProto(lhr) {
onlyCategories,
channel,
throttling,
screenEmulation,
throttlingMethod};
}

Expand Down
49 changes: 24 additions & 25 deletions core/test/lib/proto-preprocessor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,10 @@ describe('processing for proto', () => {
});

it('keeps only necessary configSettings', () => {
const samplejson = JSON.parse(JSON.stringify(sampleJson));
const {configSettings} = samplejson;
const input = {
'configSettings': {
'output': [
'json',
],
'maxWaitForLoad': 45000,
'throttlingMethod': 'devtools',
'throttling': {
'rttMs': 150,
'throughputKbps': 1638.4,
'requestLatencyMs': 562.5,
'downloadThroughputKbps': 1474.5600000000002,
'uploadThroughputKbps': 675,
'cpuSlowdownMultiplier': 4,
},
'gatherMode': false,
'disableStorageReset': false,
'formFactor': 'mobile',
'locale': 'en-US',
'blockedUrlPatterns': null,
'additionalTraceCategories': null,
'extraHeaders': null,
'onlyAudits': null,
'onlyCategories': null,
'skipAudits': null,
},
configSettings,
};
const expectation = {
'configSettings': {
Expand All @@ -57,6 +35,27 @@ describe('processing for proto', () => {
const output = processForProto(input);

expect(output).toMatchObject(expectation);
expect(Object.keys(output.configSettings)).toMatchInlineSnapshot(`
Array [
"formFactor",
"locale",
"onlyCategories",
"channel",
"throttling",
"screenEmulation",
"throttlingMethod",
]
`);
// This must be correctly populated for appropriate report metablock rendering
expect(output.configSettings.screenEmulation).toMatchInlineSnapshot(`
Object {
"deviceScaleFactor": 1.75,
"disabled": false,
"height": 823,
"mobile": true,
"width": 412,
}
`);
});

it('cleans up default runtimeErrors', () => {
Expand Down
18 changes: 17 additions & 1 deletion proto/lighthouse-result.proto
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ message LighthouseResult {

// The method used to throttle the network.
string throttling_method = 8;

message ScreenEmulation {
// Overriding width value in pixels (minimum 0, maximum 10000000). 0 disables the override.
double width = 1;
// Overriding height value in pixels (minimum 0, maximum 10000000). 0 disables the override.
double height = 2;
// Overriding device scale factor value. 0 disables the override.
double deviceScaleFactor = 3;
// Whether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text autosizing and more.
bool mobile = 4;
// Whether screen emulation is disabled. If true, the other emulation settings are ignored.
bool disabled = 5;
}

// Screen emulation properties (width, height, dpr, mobile viewport) to apply or an object of `{disabled: true}` if Lighthouse should avoid applying screen emulation. If either emulation is applied outside of Lighthouse, or it's being run on a mobile device, it typically should be set to disabled. For desktop, we recommend applying consistent desktop screen emulation.
ScreenEmulation screen_emulation = 9;
}

// The settings that were used to run this audit
Expand Down Expand Up @@ -633,4 +649,4 @@ message LhrEntity {

// A list of URL origin strings that belong to this entity.
repeated string origins = 6;
}
}