Skip to content

Commit

Permalink
misc(proto): add screenEmulation to configSettings (#14809)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish authored Feb 21, 2023
1 parent c958468 commit 0386b9b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
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;
}
}

0 comments on commit 0386b9b

Please sign in to comment.