diff --git a/docs/configuration.md b/docs/configuration.md index 492059087..2ae8028de 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -218,6 +218,7 @@ Options: --puppeteerLaunchOptions The object of puppeteer launch options --psiApiKey [psi only] The API key to use for PageSpeed Insights runner method. You do not need to use this unless you wrote a custom version. + --psiStrategy [psi only] The strategy to use for PageSpeed Insights runner method. Use mobile or desktop. The default value is mobile --startServerCommand The command to run to start the server. --startServerReadyPattern String pattern to listen for started server. [string] [default: "listen|ready"] @@ -338,6 +339,12 @@ _method=psi only_ The API endpoint to hit for making a PageSpeed Insights request. It is very unlikely you should need to use this option. Only use this if you have self-hosted a custom version of the PSI API. +#### `psiStrategy` + +_method=psi only_ + +Use this option to change the strategy to use for PageSpeed Insights runner method. Use `mobile` or `desktop`. The default value is `mobile`. + #### `startServerCommand` The shell command to use to start the project's webserver. LHCI will use this command to start the server before loading the `url`s and automatically shut it down once collection is complete. diff --git a/packages/cli/src/collect/collect.js b/packages/cli/src/collect/collect.js index 2ef6ec763..eae748f1d 100644 --- a/packages/cli/src/collect/collect.js +++ b/packages/cli/src/collect/collect.js @@ -46,6 +46,10 @@ function buildCommand(yargs) { psiApiKey: { description: '[psi only] The API key to use for PageSpeed Insights runner method.', }, + psiStrategy: { + description: + '[psi only] The strategy to use for PageSpeed Insights runner method. Use mobile or desktop. The default value is mobile', + }, staticDistDir: { description: 'The build directory where your HTML files to run Lighthouse on are located.', }, diff --git a/packages/cli/src/collect/psi-runner.js b/packages/cli/src/collect/psi-runner.js index d190aefab..5bd6c72fa 100644 --- a/packages/cli/src/collect/psi-runner.js +++ b/packages/cli/src/collect/psi-runner.js @@ -17,7 +17,7 @@ class PsiRunner { const apiKey = options.psiApiKey; if (!apiKey) throw new Error('PSI API key must be provided to use the PSI runner'); const client = new PsiClient({apiKey, endpointURL: options.psiApiEndpoint}); - return JSON.stringify(await client.run(url)); + return JSON.stringify(await client.run(url, {strategy: options.psiStrategy})); } /** diff --git a/packages/utils/src/psi-runner.js b/packages/utils/src/psi-runner.js index 4b3afa74c..0dbd1a0dd 100644 --- a/packages/utils/src/psi-runner.js +++ b/packages/utils/src/psi-runner.js @@ -19,7 +19,7 @@ class PsiRunner { /** * @param {string} url - * @param {{psiApiKey?: string, psiApiEndpoint?: string}} [options] + * @param {{psiApiKey?: string, psiApiEndpoint?: string, psiStrategy?: 'mobile'|'desktop'}} [options] * @return {Promise} */ async run(url, options) { @@ -27,7 +27,7 @@ class PsiRunner { const apiKey = options.psiApiKey; if (!apiKey) throw new Error('PSI API key must be provided to use the PSI runner'); const client = new PsiClient({apiKey, endpointURL: options.psiApiEndpoint}); - return JSON.stringify(await client.run(url)); + return JSON.stringify(await client.run(url, {strategy: options.psiStrategy})); } /** diff --git a/types/collect.d.ts b/types/collect.d.ts index 09922e9d8..491bd728f 100644 --- a/types/collect.d.ts +++ b/types/collect.d.ts @@ -47,6 +47,7 @@ declare global { autodiscoverUrlBlocklist?: string | string[]; psiApiKey?: string; psiApiEndpoint?: string; + psiStrategy?: 'mobile'|'desktop'; staticDistDir?: string; isSinglePageApplication?: boolean; startServerCommand?: string;