From 9758cae029f90908c4b5340561d9c51c26aa2f21 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Fri, 5 May 2023 10:32:58 +0200 Subject: [PATCH] fix: rename PUPPETEER_DOWNLOAD_HOST to PUPPETEER_DOWNLOAD_BASE_URL (#10130) --- docs/api/puppeteer.configuration.md | 4 +-- docs/browsers-api/browsers.installoptions.md | 18 +++++------ packages/browsers/src/install.ts | 2 +- .../src/common/Configuration.ts | 10 +++--- .../puppeteer-core/src/node/ChromeLauncher.ts | 3 +- packages/puppeteer/src/getConfiguration.ts | 31 ++++++++++++++----- packages/puppeteer/src/node/install.ts | 6 ++-- 7 files changed, 42 insertions(+), 32 deletions(-) diff --git a/docs/api/puppeteer.configuration.md b/docs/api/puppeteer.configuration.md index 47f13912..398f1f50 100644 --- a/docs/api/puppeteer.configuration.md +++ b/docs/api/puppeteer.configuration.md @@ -21,10 +21,10 @@ export interface Configuration | browserRevision | optional | string |

Specifies a certain version of the browser you'd like Puppeteer to use.

Can be overridden by PUPPETEER_BROWSER_REVISION.

See [puppeteer.launch](./puppeteer.puppeteernode.launch.md) on how executable path is inferred.

| A compatible-revision of the browser. | | cacheDirectory | optional | string |

Defines the directory to be used by Puppeteer for caching.

Can be overridden by PUPPETEER_CACHE_DIR.

| path.join(os.homedir(), '.cache', 'puppeteer') | | defaultProduct | optional | [Product](./puppeteer.product.md) |

Specifies which browser you'd like Puppeteer to use.

Can be overridden by PUPPETEER_PRODUCT.

| chrome | -| downloadHost | optional | string |

Specifies the URL prefix that is used to download the browser.

Can be overridden by PUPPETEER_DOWNLOAD_HOST.

| Either https://storage.googleapis.com or https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central, depending on the product. | +| downloadBaseUrl | optional | string |

Specifies the URL prefix that is used to download the browser.

Can be overridden by PUPPETEER_DOWNLOAD_BASE_URL.

| Either https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing or https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central, depending on the product. | | downloadPath | optional | string |

Specifies the path for the downloads folder.

Can be overridden by PUPPETEER_DOWNLOAD_PATH.

| <cache>/<product> where <cache> is Puppeteer's cache directory and <product> is the name of the browser. | | executablePath | optional | string |

Specifies an executable path to be used in [puppeteer.launch](./puppeteer.puppeteernode.launch.md).

Can be overridden by PUPPETEER_EXECUTABLE_PATH.

| **Auto-computed.** | | experiments | optional | [ExperimentsConfiguration](./puppeteer.experimentsconfiguration.md) | Defines experimental options for Puppeteer. | | -| logLevel | optional | 'silent' \| 'error' \| 'warn' |

Tells Puppeteer to log at the given level.

At the moment, any option silences logging.

| undefined | +| logLevel | optional | 'silent' \| 'error' \| 'warn' | Tells Puppeteer to log at the given level. | warn | | skipDownload | optional | boolean |

Tells Puppeteer to not download during installation.

Can be overridden by PUPPETEER_SKIP_DOWNLOAD.

| | | temporaryDirectory | optional | string |

Defines the directory to be used by Puppeteer for creating temporary files.

Can be overridden by PUPPETEER_TMP_DIR.

| os.tmpdir() | diff --git a/docs/browsers-api/browsers.installoptions.md b/docs/browsers-api/browsers.installoptions.md index ab0731df..a013e10a 100644 --- a/docs/browsers-api/browsers.installoptions.md +++ b/docs/browsers-api/browsers.installoptions.md @@ -12,12 +12,12 @@ export interface InstallOptions ## Properties -| Property | Modifiers | Type | Description | Default | -| ------------------------ | --------------------- | -------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | -| baseUrl | optional | string | Determines the host that will be used for downloading. |

Either

- https://storage.googleapis.com/chromium-browser-snapshots or - https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central

| -| browser | | [Browser](./browsers.browser.md) | Determines which browser to install. | | -| buildId | | string | Determines which buildId to dowloand. BuildId should uniquely identify binaries and they are used for caching. | | -| cacheDir | | string | Determines the path to download browsers to. | | -| downloadProgressCallback | optional | (downloadedBytes: number, totalBytes: number) => void | Provides information about the progress of the download. | | -| platform | optional | [BrowserPlatform](./browsers.browserplatform.md) | Determines which platform the browser will be suited for. | **Auto-detected.** | -| unpack | optional | boolean | Whether to unpack and install browser archives. | true | +| Property | Modifiers | Type | Description | Default | +| ------------------------ | --------------------- | -------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| baseUrl | optional | string | Determines the host that will be used for downloading. |

Either

- https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing or - https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central

| +| browser | | [Browser](./browsers.browser.md) | Determines which browser to install. | | +| buildId | | string | Determines which buildId to dowloand. BuildId should uniquely identify binaries and they are used for caching. | | +| cacheDir | | string | Determines the path to download browsers to. | | +| downloadProgressCallback | optional | (downloadedBytes: number, totalBytes: number) => void | Provides information about the progress of the download. | | +| platform | optional | [BrowserPlatform](./browsers.browserplatform.md) | Determines which platform the browser will be suited for. | **Auto-detected.** | +| unpack | optional | boolean | Whether to unpack and install browser archives. | true | diff --git a/packages/browsers/src/install.ts b/packages/browsers/src/install.ts index 054e0484..6e9b5bee 100644 --- a/packages/browsers/src/install.ts +++ b/packages/browsers/src/install.ts @@ -84,7 +84,7 @@ export interface InstallOptions { * * @defaultValue Either * - * - https://storage.googleapis.com/chromium-browser-snapshots or + * - https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing or * - https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central * */ diff --git a/packages/puppeteer-core/src/common/Configuration.ts b/packages/puppeteer-core/src/common/Configuration.ts index 6db94c34..80e866eb 100644 --- a/packages/puppeteer-core/src/common/Configuration.ts +++ b/packages/puppeteer-core/src/common/Configuration.ts @@ -56,16 +56,16 @@ export interface Configuration { /** * Specifies the URL prefix that is used to download the browser. * - * Can be overridden by `PUPPETEER_DOWNLOAD_HOST`. + * Can be overridden by `PUPPETEER_DOWNLOAD_BASE_URL`. * * @remarks * This must include the protocol and may even need a path prefix. * - * @defaultValue Either https://storage.googleapis.com or + * @defaultValue Either https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing or * https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central, * depending on the product. */ - downloadHost?: string; + downloadBaseUrl?: string; /** * Specifies the path for the downloads folder. * @@ -109,9 +109,7 @@ export interface Configuration { /** * Tells Puppeteer to log at the given level. * - * At the moment, any option silences logging. - * - * @defaultValue `undefined` + * @defaultValue `warn` */ logLevel?: 'silent' | 'error' | 'warn'; /** diff --git a/packages/puppeteer-core/src/node/ChromeLauncher.ts b/packages/puppeteer-core/src/node/ChromeLauncher.ts index 9594ed33..7301e2df 100644 --- a/packages/puppeteer-core/src/node/ChromeLauncher.ts +++ b/packages/puppeteer-core/src/node/ChromeLauncher.ts @@ -48,8 +48,7 @@ export class ChromeLauncher extends ProductLauncher { const headless = options.headless ?? true; if ( headless === true && - (!this.puppeteer.configuration.logLevel || - this.puppeteer.configuration.logLevel === 'warn') && + this.puppeteer.configuration.logLevel === 'warn' && !Boolean(process.env['PUPPETEER_DISABLE_HEADLESS_WARNING']) ) { console.warn( diff --git a/packages/puppeteer/src/getConfiguration.ts b/packages/puppeteer/src/getConfiguration.ts index d682bac4..462ea593 100644 --- a/packages/puppeteer/src/getConfiguration.ts +++ b/packages/puppeteer/src/getConfiguration.ts @@ -24,6 +24,12 @@ export const getConfiguration = (): Configuration => { const result = cosmiconfigSync('puppeteer').search(); const configuration: Configuration = result ? result.config : {}; + configuration.logLevel = (process.env['PUPPETEER_LOGLEVEL'] ?? + process.env['npm_config_LOGLEVEL'] ?? + process.env['npm_package_config_LOGLEVEL'] ?? + configuration.logLevel ?? + 'warn') as 'silent' | 'error' | 'warn'; + // Merging environment variables. configuration.defaultProduct = (process.env['PUPPETEER_PRODUCT'] ?? process.env['npm_config_puppeteer_product'] ?? @@ -57,11 +63,25 @@ export const getConfiguration = (): Configuration => { process.env['npm_config_puppeteer_browser_revision'] ?? process.env['npm_package_config_puppeteer_browser_revision'] ?? configuration.browserRevision; - configuration.downloadHost = + + const downloadHost = process.env['PUPPETEER_DOWNLOAD_HOST'] ?? process.env['npm_config_puppeteer_download_host'] ?? - process.env['npm_package_config_puppeteer_download_host'] ?? - configuration.downloadHost; + process.env['npm_package_config_puppeteer_download_host']; + + if (downloadHost && configuration.logLevel === 'warn') { + console.warn( + `PUPPETEER_DOWNLOAD_HOST is deprecated. Use PUPPETEER_DOWNLOAD_BASE_URL instead.` + ); + } + + configuration.downloadBaseUrl = + process.env['PUPPETEER_DOWNLOAD_BASE_URL'] ?? + process.env['npm_config_puppeteer_download_base_url'] ?? + process.env['npm_package_config_puppeteer_download_base_url'] ?? + configuration.downloadBaseUrl ?? + downloadHost; + configuration.downloadPath = process.env['PUPPETEER_DOWNLOAD_PATH'] ?? process.env['npm_config_puppeteer_download_path'] ?? @@ -83,11 +103,6 @@ export const getConfiguration = (): Configuration => { configuration.experiments ??= {}; - configuration.logLevel = (process.env['PUPPETEER_LOGLEVEL'] ?? - process.env['npm_config_LOGLEVEL'] ?? - process.env['npm_package_config_LOGLEVEL'] ?? - configuration.logLevel) as 'silent' | 'error' | 'warn'; - // Validate configuration. if (!isSupportedProduct(configuration.defaultProduct)) { throw new Error(`Unsupported product ${configuration.defaultProduct}`); diff --git a/packages/puppeteer/src/node/install.ts b/packages/puppeteer/src/node/install.ts index f3cd7587..5017c957 100644 --- a/packages/puppeteer/src/node/install.ts +++ b/packages/puppeteer/src/node/install.ts @@ -46,7 +46,7 @@ export async function downloadBrowser(): Promise { return; } - const downloadHost = configuration.downloadHost; + const downloadBaseUrl = configuration.downloadBaseUrl; const platform = detectBrowserPlatform(); if (!platform) { @@ -68,9 +68,7 @@ export async function downloadBrowser(): Promise { platform, buildId, downloadProgressCallback: makeProgressCallback(browser, buildId), - // TODO: remove downloadHost in favour of baseDownloadUrl. The "host" of - // Firefox is already a URL and not a host. This would be a breaking change. - baseUrl: downloadHost, + baseUrl: downloadBaseUrl, }); logPolitely(