diff --git a/packages/playwright-core/src/cli/program.ts b/packages/playwright-core/src/cli/program.ts index 6cf0403446..c27b6d2be4 100644 --- a/packages/playwright-core/src/cli/program.ts +++ b/packages/playwright-core/src/cli/program.ts @@ -146,7 +146,8 @@ program .option('--force', 'force reinstall of stable browser channels') .option('--only-shell', 'only install headless shell when installing chromium') .option('--no-shell', 'do not install chromium headless shell') - .action(async function(args: string[], options: { withDeps?: boolean, force?: boolean, dryRun?: boolean, shell?: boolean, noShell?: boolean, onlyShell?: boolean }) { + .option('--quiet', 'hide logs while installing') + .action(async function(args: string[], options: { withDeps?: boolean, force?: boolean, dryRun?: boolean, shell?: boolean, noShell?: boolean, onlyShell?: boolean, quiet?: boolean }) { // For '--no-shell' option, commander sets `shell: false` instead. if (options.shell === false) options.noShell = true; @@ -190,7 +191,8 @@ program } } else { const forceReinstall = hasNoArguments ? false : !!options.force; - await registry.install(executables, forceReinstall); + const suppressLogs = options.quiet; + await registry.install(executables, forceReinstall, suppressLogs); await registry.validateHostRequirementsForExecutablesIfNeeded(executables, process.env.PW_LANG_NAME || 'javascript').catch((e: Error) => { e.name = 'Playwright Host validation warning'; console.error(e); diff --git a/packages/playwright-core/src/server/registry/browserFetcher.ts b/packages/playwright-core/src/server/registry/browserFetcher.ts index 3a6e36b42d..3f145fb2ee 100644 --- a/packages/playwright-core/src/server/registry/browserFetcher.ts +++ b/packages/playwright-core/src/server/registry/browserFetcher.ts @@ -27,7 +27,7 @@ import { browserDirectoryToMarkerFilePath } from '.'; import { getUserAgent } from '../../utils/userAgent'; import type { DownloadParams } from './oopDownloadBrowserMain'; -export async function downloadBrowserWithProgressBar(title: string, browserDirectory: string, executablePath: string | undefined, downloadURLs: string[], downloadFileName: string, downloadConnectionTimeout: number): Promise { +export async function downloadBrowserWithProgressBar(title: string, browserDirectory: string, executablePath: string | undefined, downloadURLs: string[], downloadFileName: string, downloadConnectionTimeout: number, quiet?: boolean): Promise { if (await existsAsync(browserDirectoryToMarkerFilePath(browserDirectory))) { // Already downloaded. debugLogger.log('install', `${title} is already downloaded.`); @@ -40,8 +40,10 @@ export async function downloadBrowserWithProgressBar(title: string, browserDirec for (let attempt = 1; attempt <= retryCount; ++attempt) { debugLogger.log('install', `downloading ${title} - attempt #${attempt}`); const url = downloadURLs[(attempt - 1) % downloadURLs.length]; - logPolitely(`Downloading ${title}` + colors.dim(` from ${url}`)); - const { error } = await downloadBrowserWithProgressBarOutOfProcess(title, browserDirectory, url, zipPath, executablePath, downloadConnectionTimeout); + if (!quiet) { + logPolitely(`Downloading ${title}` + colors.dim(` from ${url}`)); + } + const { error } = await downloadBrowserWithProgressBarOutOfProcess(title, browserDirectory, url, zipPath, executablePath, downloadConnectionTimeout, quiet); if (!error) { debugLogger.log('install', `SUCCESS installing ${title}`); break; @@ -63,7 +65,9 @@ export async function downloadBrowserWithProgressBar(title: string, browserDirec if (await existsAsync(zipPath)) await fs.promises.unlink(zipPath); } - logPolitely(`${title} downloaded to ${browserDirectory}`); + if (!quiet) { + logPolitely(`${title} downloaded to ${browserDirectory}`); + } return true; } @@ -72,16 +76,18 @@ export async function downloadBrowserWithProgressBar(title: string, browserDirec * Thats why we execute it in a separate process and check manually if the destination file exists. * https://github.com/microsoft/playwright/issues/17394 */ -function downloadBrowserWithProgressBarOutOfProcess(title: string, browserDirectory: string, url: string, zipPath: string, executablePath: string | undefined, connectionTimeout: number): Promise<{ error: Error | null }> { +function downloadBrowserWithProgressBarOutOfProcess(title: string, browserDirectory: string, url: string, zipPath: string, executablePath: string | undefined, connectionTimeout: number, quiet?: boolean): Promise<{ error: Error | null }> { const cp = childProcess.fork(path.join(__dirname, 'oopDownloadBrowserMain.js')); const promise = new ManualPromise<{ error: Error | null }>(); - const progress = getDownloadProgress(); - cp.on('message', (message: any) => { - if (message?.method === 'log') - debugLogger.log('install', message.params.message); - if (message?.method === 'progress') - progress(message.params.done, message.params.total); - }); + if (!quiet) { + const progress = getDownloadProgress(); + cp.on('message', (message: any) => { + if (message?.method === 'log') + debugLogger.log('install', message.params.message); + if (message?.method === 'progress') + progress(message.params.done, message.params.total); + }); + } cp.on('exit', code => { if (code !== 0) { promise.resolve({ error: new Error(`Download failure, code=${code}`) }); diff --git a/packages/playwright-core/src/server/registry/index.ts b/packages/playwright-core/src/server/registry/index.ts index cd2f2f1d32..64d865ea12 100644 --- a/packages/playwright-core/src/server/registry/index.ts +++ b/packages/playwright-core/src/server/registry/index.ts @@ -429,7 +429,7 @@ export interface Executable { } interface ExecutableImpl extends Executable { - _install?: () => Promise; + _install?: (quiet?: boolean) => Promise; _dependencyGroup?: DependencyGroup; _isHermeticInstallation?: boolean; } @@ -491,7 +491,7 @@ export class Registry { _validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, chromium.dir, ['chrome-linux'], [], ['chrome-win']), downloadURLs: this._downloadURLs(chromium), browserVersion: chromium.browserVersion, - _install: () => this._downloadExecutable(chromium, chromiumExecutable), + _install: (quiet?: boolean) => this._downloadExecutable(chromium, chromiumExecutable, quiet), _dependencyGroup: 'chromium', _isHermeticInstallation: true, }); @@ -509,7 +509,7 @@ export class Registry { _validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, chromiumHeadlessShell.dir, ['chrome-linux'], [], ['chrome-win']), downloadURLs: this._downloadURLs(chromiumHeadlessShell), browserVersion: chromium.browserVersion, - _install: () => this._downloadExecutable(chromiumHeadlessShell, chromiumHeadlessShellExecutable), + _install: (quiet?: boolean) => this._downloadExecutable(chromiumHeadlessShell, chromiumHeadlessShellExecutable, quiet), _dependencyGroup: 'chromium', _isHermeticInstallation: true, }); @@ -527,7 +527,7 @@ export class Registry { _validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, chromiumTipOfTree.dir, ['chrome-linux'], [], ['chrome-win']), downloadURLs: this._downloadURLs(chromiumTipOfTree), browserVersion: chromiumTipOfTree.browserVersion, - _install: () => this._downloadExecutable(chromiumTipOfTree, chromiumTipOfTreeExecutable), + _install: (quiet?: boolean) => this._downloadExecutable(chromiumTipOfTree, chromiumTipOfTreeExecutable, quiet), _dependencyGroup: 'chromium', _isHermeticInstallation: true, }); @@ -637,7 +637,7 @@ export class Registry { _validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, chromium.dir, ['chrome-linux'], [], ['chrome-win']), downloadURLs: this._downloadURLs(chromium), browserVersion: chromium.browserVersion, - _install: () => this._downloadExecutable(chromium, chromiumExecutable), + _install: (quiet?: boolean) => this._downloadExecutable(chromium, chromiumExecutable, quiet), _dependencyGroup: 'chromium', _isHermeticInstallation: true, }); @@ -655,7 +655,7 @@ export class Registry { _validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, firefox.dir, ['firefox'], [], ['firefox']), downloadURLs: this._downloadURLs(firefox), browserVersion: firefox.browserVersion, - _install: () => this._downloadExecutable(firefox, firefoxExecutable), + _install: (quiet?: boolean) => this._downloadExecutable(firefox, firefoxExecutable, quiet), _dependencyGroup: 'firefox', _isHermeticInstallation: true, }); @@ -673,7 +673,7 @@ export class Registry { _validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, firefoxBeta.dir, ['firefox'], [], ['firefox']), downloadURLs: this._downloadURLs(firefoxBeta), browserVersion: firefoxBeta.browserVersion, - _install: () => this._downloadExecutable(firefoxBeta, firefoxBetaExecutable), + _install: (quiet?: boolean) => this._downloadExecutable(firefoxBeta, firefoxBetaExecutable, quiet), _dependencyGroup: 'firefox', _isHermeticInstallation: true, }); @@ -701,7 +701,7 @@ export class Registry { _validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, webkit.dir, webkitLinuxLddDirectories, ['libGLESv2.so.2', 'libx264.so'], ['']), downloadURLs: this._downloadURLs(webkit), browserVersion: webkit.browserVersion, - _install: () => this._downloadExecutable(webkit, webkitExecutable), + _install: (quiet?: boolean) => this._downloadExecutable(webkit, webkitExecutable, quiet), _dependencyGroup: 'webkit', _isHermeticInstallation: true, }); @@ -718,7 +718,7 @@ export class Registry { installType: ffmpeg.installByDefault ? 'download-by-default' : 'download-on-demand', _validateHostRequirements: () => Promise.resolve(), downloadURLs: this._downloadURLs(ffmpeg), - _install: () => this._downloadExecutable(ffmpeg, ffmpegExecutable), + _install: (quiet?: boolean) => this._downloadExecutable(ffmpeg, ffmpegExecutable, quiet), _dependencyGroup: 'tools', _isHermeticInstallation: true, }); @@ -911,7 +911,7 @@ export class Registry { return await installDependenciesLinux(targets, dryRun); } - async install(executablesToInstall: Executable[], forceReinstall: boolean) { + async install(executablesToInstall: Executable[], forceReinstall: boolean, quiet?: boolean) { const executables = this._dedupe(executablesToInstall); await fs.promises.mkdir(registryDirectory, { recursive: true }); const lockfilePath = path.join(registryDirectory, '__dirlock'); @@ -963,7 +963,7 @@ export class Registry { `<3 Playwright Team`, ].join('\n'), 1)); } - await executable._install(); + await executable._install(quiet); } } catch (e) { if (e.code === 'ELOCKED') { @@ -1060,7 +1060,7 @@ export class Registry { return downloadURLs; } - private async _downloadExecutable(descriptor: BrowsersJSONDescriptor, executablePath?: string) { + private async _downloadExecutable(descriptor: BrowsersJSONDescriptor, executablePath?: string, quiet?: boolean) { const downloadURLs = this._downloadURLs(descriptor); if (!downloadURLs.length) throw new Error(`ERROR: Playwright does not support ${descriptor.name} on ${hostPlatform}`); @@ -1084,7 +1084,7 @@ export class Registry { const downloadFileName = `playwright-download-${descriptor.name}-${hostPlatform}-${descriptor.revision}.zip`; const downloadConnectionTimeoutEnv = getFromENV('PLAYWRIGHT_DOWNLOAD_CONNECTION_TIMEOUT'); const downloadConnectionTimeout = +(downloadConnectionTimeoutEnv || '0') || 30_000; - await downloadBrowserWithProgressBar(title, descriptor.dir, executablePath, downloadURLs, downloadFileName, downloadConnectionTimeout).catch(e => { + await downloadBrowserWithProgressBar(title, descriptor.dir, executablePath, downloadURLs, downloadFileName, downloadConnectionTimeout, quiet).catch(e => { throw new Error(`Failed to download ${title}, caused by\n${e.stack}`); }); }