diff --git a/cli/test/cli/run-test.js b/cli/test/cli/run-test.js index 0b866324c39e..c65864b26160 100644 --- a/cli/test/cli/run-test.js +++ b/cli/test/cli/run-test.js @@ -37,6 +37,7 @@ describe('CLI run', function() { const flags = getFlags([ '--output=json', + `--extra-headers '{"Cookie":"monster=blue"}'`, `--output-path=${filename}`, '--plugins=lighthouse-plugin-simple', // Use sample artifacts to avoid gathering during a unit test. diff --git a/core/lib/proto-preprocessor.js b/core/lib/proto-preprocessor.js index e025f733d981..63c65160fee7 100644 --- a/core/lib/proto-preprocessor.js +++ b/core/lib/proto-preprocessor.js @@ -22,29 +22,12 @@ function processForProto(lhr) { /** @type {LH.Result} */ const reportJson = JSON.parse(JSON.stringify(lhr)); - // Clean up the configSettings - // Note: This is not strictly required for conversion if protobuf parsing is set to - // 'ignore unknown fields' in the language of conversion. + // Drop these fields as we've omitted them from the proto for simplicity if (reportJson.configSettings) { - // The settings that are in both proto and LHR - const { - formFactor, - locale, - onlyCategories, - channel, - throttling, - screenEmulation, - throttlingMethod} = reportJson.configSettings; - - // @ts-expect-error - intentionally only a subset of settings. - reportJson.configSettings = { - formFactor, - locale, - onlyCategories, - channel, - throttling, - screenEmulation, - throttlingMethod}; + // @ts-expect-error Removing non-optional field. + delete reportJson.configSettings.auditMode; + // @ts-expect-error Removing non-optional field. + delete reportJson.configSettings.gatherMode; } // Remove runtimeError if it is NO_ERROR diff --git a/core/test/lib/proto-preprocessor-test.js b/core/test/lib/proto-preprocessor-test.js index 59c859cda868..336beb4bc58c 100644 --- a/core/test/lib/proto-preprocessor-test.js +++ b/core/test/lib/proto-preprocessor-test.js @@ -37,13 +37,35 @@ describe('processing for proto', () => { expect(output).toMatchObject(expectation); expect(Object.keys(output.configSettings)).toMatchInlineSnapshot(` Array [ + "output", + "maxWaitForFcp", + "maxWaitForLoad", + "pauseAfterFcpMs", + "pauseAfterLoadMs", + "networkQuietThresholdMs", + "cpuQuietThresholdMs", "formFactor", - "locale", - "onlyCategories", - "channel", "throttling", - "screenEmulation", "throttlingMethod", + "screenEmulation", + "emulatedUserAgent", + "clearStorageTypes", + "disableStorageReset", + "debugNavigation", + "channel", + "usePassiveGathering", + "disableFullPageScreenshot", + "skipAboutBlank", + "blankPage", + "ignoreStatusCode", + "locale", + "blockedUrlPatterns", + "additionalTraceCategories", + "extraHeaders", + "precomputedLanternData", + "onlyAudits", + "onlyCategories", + "skipAudits", ] `); // This must be correctly populated for appropriate report metablock rendering diff --git a/core/test/results/artifacts/artifacts.json b/core/test/results/artifacts/artifacts.json index c86942e94961..2ca5e940cad3 100644 --- a/core/test/results/artifacts/artifacts.json +++ b/core/test/results/artifacts/artifacts.json @@ -458,7 +458,9 @@ "locale": "en-US", "blockedUrlPatterns": null, "additionalTraceCategories": null, - "extraHeaders": null, + "extraHeaders": { + "Cookie": "monster=blue" + }, "precomputedLanternData": null, "onlyAudits": null, "onlyCategories": null, diff --git a/core/test/results/sample-config.js b/core/test/results/sample-config.js index e711264b3e71..9133480728df 100644 --- a/core/test/results/sample-config.js +++ b/core/test/results/sample-config.js @@ -13,6 +13,9 @@ const sampleConfig = { extends: 'lighthouse:default', settings: { throttlingMethod: 'devtools', + extraHeaders: { + 'Cookie': 'monster=blue', + }, }, }; diff --git a/core/test/results/sample_v2.json b/core/test/results/sample_v2.json index 1608a93ce6ea..f1552dfcbab0 100644 --- a/core/test/results/sample_v2.json +++ b/core/test/results/sample_v2.json @@ -7243,7 +7243,9 @@ "locale": "en-US", "blockedUrlPatterns": null, "additionalTraceCategories": null, - "extraHeaders": null, + "extraHeaders": { + "Cookie": "monster=blue" + }, "precomputedLanternData": null, "onlyAudits": null, "onlyCategories": null, diff --git a/proto/README.md b/proto/README.md index d7aaf829d07b..e9bc853fc344 100644 --- a/proto/README.md +++ b/proto/README.md @@ -5,7 +5,7 @@ You'll need to have **`v3.20+`** of protobuf. Note that they [changed the versioning scheme](https://developers.google.com/protocol-buffers/docs/news/2022-05-06#versioning) and went from `3.20.1` to `4.21.0`. Making it more confusing, in `brew` and Github, `4.21.x` is shown as `v21.x`. -1. Install the proto compiler with `brew install protobuf`, or something [like this](https://github.com/GoogleChrome/lighthouse/blob/9fd45c5e2b92e3b1f10b642ea631dd5a9598f5ee/.github/workflows/unit.yml#L32-L45). +1. Install the proto compiler with `brew install protobuf`, or something [like this](https://github.com/GoogleChrome/lighthouse/blob/9fd45c5e2b92e3b1f10b642ea631dd5a9598f5ee/.github/workflows/unit.yml#L32-L45). Note: it's a good idea to [use a virtual environment](https://realpython.com/python-virtual-environments-a-primer/) rather than installing it globally 1. Run `yarn test-proto` ## Proto Resources diff --git a/proto/lighthouse-result.proto b/proto/lighthouse-result.proto index 7889f5b04dbb..c33695a29319 100644 --- a/proto/lighthouse-result.proto +++ b/proto/lighthouse-result.proto @@ -132,7 +132,7 @@ message LighthouseResult { map category_groups = 11; // Message containing the configuration settings for the LH run - // Next ID: 11 + // Next ID: 33 message ConfigSettings { // The possible form factors an audit can be run in. // This enum served the emulated_form_factor field, but in v7, that field @@ -193,11 +193,11 @@ message LighthouseResult { string throttling_method = 8; message ScreenEmulation { - // Overriding width value in pixels (minimum 0, maximum 10000000). 0 - // disables the override. + // 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. + // 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; @@ -217,8 +217,85 @@ message LighthouseResult { // screen emulation. ScreenEmulation screen_emulation = 9; + // Indicating whether Lighthouse should ignore status codes. bool ignore_status_code = 10; + + // The type(s) of report output to be produced. + // Can be a string of 'json' | 'html' | 'csv' + // Or an array of those strings + google.protobuf.Value output = 11; + + // The maximum amount of time to wait for a page content render, in ms. If + // no content is rendered within this limit, the run is aborted with an + // error. + int32 max_wait_for_fcp = 12; + // The maximum amount of time to wait for a page to load, in ms. + int32 max_wait_for_load = 13; + // The number of milliseconds to wait after FCP until the page should be + // considered loaded. + int32 pause_after_fcp_ms = 14; + // The number of milliseconds to wait after the load event until the page + // should be considered loaded. + int32 pause_after_load_ms = 15; + // The number of milliseconds to wait between high priority network requests + // or 3 simultaneous requests before the page should be considered loaded. + int32 network_quiet_threshold_ms = 16; + // The number of milliseconds to wait between long tasks until the page + // should be considered loaded. + int32 cpu_quiet_threshold_ms = 17; + + // User Agent string to apply, `false` to not change the host's UA string, + // or `true` to use Lighthouse's default UA string. + string emulated_user_agent = 18; + + // audit_mode and gather_mode are excluded from the proto, as they are boolean/string and niche enough that we don't want to deal with them. + + // Flag indicating that the browser storage should not be reset for the + // audit. + bool disable_storage_reset = 19; + // Flag indicating that Lighthouse should pause after page load to wait for + // the user's permission to continue the audit. + bool debug_navigation = 20; + // If set to true, gatherers should avoid any behavior that may be + // destructive to the page state. (e.g. extra navigations, resizing the + // viewport) + bool use_passive_gathering = 21; + // Disables collection of the full page screenshot, which can be rather + // large and possibly leave the page in an undesirable state. + bool disable_full_page_screenshot = 22; + // If set to true, will skip the initial navigation to about:blank. + bool skip_about_blank = 23; + // The URL to use for the "blank" neutral page in between navigations. + // Defaults to `about:blank`. + string blank_page = 24; + + // List of URL patterns to block. + repeated string blocked_url_patterns = 25; + + // Comma-delimited list of trace categories to include. + string additional_trace_categories = 26; + + // If present, the run should only conduct this list of audits. + repeated string only_audits = 27; + // If present, the run should skip this list of audits. + repeated string skip_audits = 28; + + // Flag indicating which kinds of browser storage should be reset for the audit. + // Cookies are not cleared by default, so the user isn't logged out. + // indexeddb, websql, and localstorage are not cleared by default to prevent + // loss of potentially important data. + // https://chromedevtools.github.io/debugger-protocol-viewer/tot/Storage/#type-StorageType + repeated string clear_storage_types = 29; + + // List of extra HTTP Headers to include + map extra_headers = 30; + + // The budget.json object for LightWallet + repeated google.protobuf.Struct budgets = 31 [deprecated = true]; + + // Precomputed lantern estimates to use instead of observed analysis. + google.protobuf.Struct precomputed_lantern_data = 32; } // The settings that were used to run this audit @@ -298,7 +375,7 @@ message LhrCategory { // This value is nullable, so is a `Value` type google.protobuf.Value score = 4; - // An description for manual audits within this category. + // A description for manual audits within this category. string manual_description = 5; // A Category's reference to an AuditResult, with a weight for category diff --git a/types/lhr/settings.d.ts b/types/lhr/settings.d.ts index b1c557a7176d..df95cb729899 100644 --- a/types/lhr/settings.d.ts +++ b/types/lhr/settings.d.ts @@ -112,7 +112,7 @@ export type ScreenEmulationSettings = { pauseAfterFcpMs?: number; /** The number of milliseconds to wait after the load event until the page should be considered loaded. */ pauseAfterLoadMs?: number; - /** The number of milliseconds to wait between high priority network requests or 3 simulataneous requests before the page should be considered loaded. */ + /** The number of milliseconds to wait between high priority network requests or 3 simultaneous requests before the page should be considered loaded. */ networkQuietThresholdMs?: number; /** The number of milliseconds to wait between long tasks until the page should be considered loaded. */ cpuQuietThresholdMs?: number;