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

fix(cli): respect collect puppeteerLaunchOptions.headless #1051

Merged
merged 1 commit into from
Jun 24, 2024
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
5 changes: 4 additions & 1 deletion packages/cli/src/collect/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ function buildCommand(yargs) {
choices: ['node', 'psi'],
default: 'node',
},
headful: {type: 'boolean', description: 'Run with a headful Chrome'},
headful: {
description:
'Run with a headful Chrome (pass `headless: false` to puppeteer). Overrides value of `puppeteerLaunchOptions.headless`',
},
additive: {type: 'boolean', description: 'Skips clearing of previous collect data'},
url: {
description:
Expand Down
11 changes: 8 additions & 3 deletions packages/cli/src/collect/puppeteer-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,19 @@ class PuppeteerManager {
throw new Error(`Unable to require 'puppeteer' for script, have you run 'npm i puppeteer'?`);
}

this._browser = await puppeteer.launch({
/** @type {import('puppeteer').PuppeteerLaunchOptions} */
const args = {
...(this._options.puppeteerLaunchOptions || {}),
headless: 'new',
pipe: false,
devtools: false,
headless: this._options.headful ? false : 'new',
// The default value for `chromePath` is determined by yargs using the `getChromiumPath` method.
executablePath: this._options.chromePath,
});
};
if (this._options.headful === true) {
args.headless = false;
}
this._browser = await puppeteer.launch(args);

return this._browser;
}
Expand Down
4 changes: 2 additions & 2 deletions types/collect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ declare global {
chromePath?: string;
puppeteerScript?: string;
/** @see https://github.com/puppeteer/puppeteer/blob/v2.0.0/docs/api.md#puppeteerlaunchoptions */
puppeteerLaunchOptions?: import('puppeteer').LaunchOptions;
puppeteerLaunchOptions?: import('puppeteer').PuppeteerLaunchOptions;
method: 'node' | 'psi';
numberOfRuns: number;
headful: boolean;
headful?: boolean;
additive: boolean;
settings?: LighthouseSettings;
maxAutodiscoverUrls?: number;
Expand Down
Loading