puppeteer
Advanced tools
Comparing version 22.15.0 to 23.0.0
@@ -30,3 +30,3 @@ "use strict"; | ||
*/ | ||
function isSupportedProduct(product) { | ||
function isSupportedBrowser(product) { | ||
switch (product) { | ||
@@ -43,2 +43,53 @@ case 'chrome': | ||
*/ | ||
function getDefaultBrowser(browser) { | ||
// Validate configuration. | ||
if (browser && !isSupportedBrowser(browser)) { | ||
throw new Error(`Unsupported browser ${browser}`); | ||
} | ||
switch (browser) { | ||
case 'firefox': | ||
return 'firefox'; | ||
default: | ||
return 'chrome'; | ||
} | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
function getLogLevel(logLevel) { | ||
switch (logLevel) { | ||
case 'silent': | ||
return 'silent'; | ||
case 'error': | ||
return 'error'; | ||
default: | ||
return 'warn'; | ||
} | ||
} | ||
function getBrowserSetting(browser, configuration, defaultConfig = {}) { | ||
if (configuration.skipDownload) { | ||
return { | ||
skipDownload: true, | ||
}; | ||
} | ||
const browserSetting = {}; | ||
const browserEnvName = browser.replaceAll('-', '_').toUpperCase(); | ||
browserSetting.version = | ||
process.env[`PUPPETEER_${browserEnvName}_VERSION`] ?? | ||
configuration[browser]?.version ?? | ||
defaultConfig.version; | ||
browserSetting.downloadBaseUrl = | ||
process.env[`PUPPETEER_${browserEnvName}_DOWNLOAD_BASE_URL`] ?? | ||
configuration[browser]?.downloadBaseUrl ?? | ||
defaultConfig.downloadBaseUrl; | ||
browserSetting.skipDownload = | ||
getBooleanEnvVar(`PUPPETEER_${browserEnvName}_SKIP_DOWNLOAD`) ?? | ||
getBooleanEnvVar(`PUPPETEER_SKIP_${browserEnvName}_DOWNLOAD`) ?? | ||
configuration[browser]?.skipDownload ?? | ||
defaultConfig.skipDownload; | ||
return browserSetting; | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
const getConfiguration = () => { | ||
@@ -49,18 +100,7 @@ const result = (0, cosmiconfig_1.cosmiconfigSync)('puppeteer', { | ||
const configuration = result ? result.config : {}; | ||
configuration.logLevel = (process.env['PUPPETEER_LOGLEVEL'] ?? | ||
process.env['npm_config_LOGLEVEL'] ?? | ||
process.env['npm_package_config_LOGLEVEL'] ?? | ||
configuration.logLevel ?? | ||
'warn'); | ||
configuration.logLevel = getLogLevel(process.env['PUPPETEER_LOGLEVEL'] ?? configuration.logLevel); | ||
// Merging environment variables. | ||
configuration.defaultProduct = (process.env['PUPPETEER_PRODUCT'] ?? | ||
process.env['npm_config_puppeteer_product'] ?? | ||
process.env['npm_package_config_puppeteer_product'] ?? | ||
configuration.defaultProduct ?? | ||
'chrome'); | ||
configuration.defaultBrowser = getDefaultBrowser(process.env['PUPPETEER_BROWSER'] ?? configuration.defaultBrowser); | ||
configuration.executablePath = | ||
process.env['PUPPETEER_EXECUTABLE_PATH'] ?? | ||
process.env['npm_config_puppeteer_executable_path'] ?? | ||
process.env['npm_package_config_puppeteer_executable_path'] ?? | ||
configuration.executablePath; | ||
process.env['PUPPETEER_EXECUTABLE_PATH'] ?? configuration.executablePath; | ||
// Default to skipDownload if executablePath is set | ||
@@ -71,58 +111,17 @@ if (configuration.executablePath) { | ||
// Set skipDownload explicitly or from default | ||
configuration.skipDownload = Boolean(getBooleanEnvVar('PUPPETEER_SKIP_DOWNLOAD') ?? | ||
getBooleanEnvVar('npm_config_puppeteer_skip_download') ?? | ||
getBooleanEnvVar('npm_package_config_puppeteer_skip_download') ?? | ||
configuration.skipDownload); | ||
// Set skipChromeDownload explicitly or from default | ||
configuration.skipChromeDownload = Boolean(getBooleanEnvVar('PUPPETEER_SKIP_CHROME_DOWNLOAD') ?? | ||
getBooleanEnvVar('npm_config_puppeteer_skip_chrome_download') ?? | ||
getBooleanEnvVar('npm_package_config_puppeteer_skip_chrome_download') ?? | ||
configuration.skipChromeDownload); | ||
// Set skipChromeDownload explicitly or from default | ||
configuration.skipChromeHeadlessShellDownload = Boolean(getBooleanEnvVar('PUPPETEER_SKIP_CHROME_HEADLESS_SHELL_DOWNLOAD') ?? | ||
getBooleanEnvVar('npm_config_puppeteer_skip_chrome_headless_shell_download') ?? | ||
getBooleanEnvVar('npm_package_config_puppeteer_skip_chrome_headless_shell_download') ?? | ||
configuration.skipChromeHeadlessShellDownload); | ||
configuration.skipDownload = | ||
getBooleanEnvVar('PUPPETEER_SKIP_DOWNLOAD') ?? configuration.skipDownload; | ||
// Prepare variables used in browser downloading | ||
if (!configuration.skipDownload) { | ||
configuration.browserRevision = | ||
process.env['PUPPETEER_BROWSER_REVISION'] ?? | ||
process.env['npm_config_puppeteer_browser_revision'] ?? | ||
process.env['npm_package_config_puppeteer_browser_revision'] ?? | ||
configuration.browserRevision; | ||
const downloadHost = process.env['PUPPETEER_DOWNLOAD_HOST'] ?? | ||
process.env['npm_config_puppeteer_download_host'] ?? | ||
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; | ||
} | ||
if (Object.keys(process.env).some(key => { | ||
return key.startsWith('npm_package_config_puppeteer_'); | ||
}) && | ||
configuration.logLevel === 'warn') { | ||
console.warn(`Configuring Puppeteer via npm/package.json is deprecated. Use https://pptr.dev/guides/configuration instead.`); | ||
} | ||
configuration.chrome = getBrowserSetting('chrome', configuration); | ||
configuration['chrome-headless-shell'] = getBrowserSetting('chrome-headless-shell', configuration); | ||
configuration.firefox = getBrowserSetting('firefox', configuration, { | ||
skipDownload: true, | ||
}); | ||
configuration.cacheDirectory = | ||
process.env['PUPPETEER_CACHE_DIR'] ?? | ||
process.env['npm_config_puppeteer_cache_dir'] ?? | ||
process.env['npm_package_config_puppeteer_cache_dir'] ?? | ||
configuration.cacheDirectory ?? | ||
(0, path_1.join)((0, os_1.homedir)(), '.cache', 'puppeteer'); | ||
configuration.temporaryDirectory = | ||
process.env['PUPPETEER_TMP_DIR'] ?? | ||
process.env['npm_config_puppeteer_tmp_dir'] ?? | ||
process.env['npm_package_config_puppeteer_tmp_dir'] ?? | ||
configuration.temporaryDirectory; | ||
process.env['PUPPETEER_TMP_DIR'] ?? configuration.temporaryDirectory; | ||
configuration.experiments ??= {}; | ||
// Validate configuration. | ||
if (!isSupportedProduct(configuration.defaultProduct)) { | ||
throw new Error(`Unsupported product ${configuration.defaultProduct}`); | ||
} | ||
return configuration; | ||
@@ -129,0 +128,0 @@ }; |
@@ -26,18 +26,18 @@ #!/usr/bin/env node | ||
[browsers_1.Browser.CHROME]: { | ||
buildId: puppeteer_js_1.default.configuration.browserRevision || | ||
buildId: puppeteer_js_1.default.configuration.chrome?.version || | ||
revisions_js_1.PUPPETEER_REVISIONS['chrome'] || | ||
'latest', | ||
skipDownload: puppeteer_js_1.default.configuration.skipChromeDownload ?? false, | ||
skipDownload: puppeteer_js_1.default.configuration.chrome?.skipDownload ?? false, | ||
}, | ||
[browsers_1.Browser.FIREFOX]: { | ||
buildId: puppeteer_js_1.default.configuration.browserRevision || | ||
buildId: puppeteer_js_1.default.configuration.firefox?.version || | ||
revisions_js_1.PUPPETEER_REVISIONS['firefox'] || | ||
'latest', | ||
skipDownload: true, | ||
skipDownload: puppeteer_js_1.default.configuration.firefox?.skipDownload ?? true, | ||
}, | ||
[browsers_1.Browser.CHROMEHEADLESSSHELL]: { | ||
buildId: puppeteer_js_1.default.configuration.browserRevision || | ||
revisions_js_1.PUPPETEER_REVISIONS['chrome'] || | ||
buildId: puppeteer_js_1.default.configuration['chrome-headless-shell']?.version || | ||
revisions_js_1.PUPPETEER_REVISIONS['chrome-headless-shell'] || | ||
'latest', | ||
skipDownload: puppeteer_js_1.default.configuration.skipChromeHeadlessShellDownload ?? false, | ||
skipDownload: puppeteer_js_1.default.configuration['chrome-headless-shell']?.skipDownload ?? false, | ||
}, | ||
@@ -44,0 +44,0 @@ }, |
@@ -9,3 +9,3 @@ /** | ||
*/ | ||
export declare function downloadBrowser(): Promise<void>; | ||
export declare function downloadBrowsers(): Promise<void>; | ||
//# sourceMappingURL=install.d.ts.map |
@@ -8,24 +8,38 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.downloadBrowser = void 0; | ||
exports.downloadBrowsers = void 0; | ||
const browsers_1 = require("@puppeteer/browsers"); | ||
const revisions_js_1 = require("puppeteer-core/internal/revisions.js"); | ||
const getConfiguration_js_1 = require("../getConfiguration.js"); | ||
async function downloadBrowser({ browser, configuration, cacheDir, platform, }) { | ||
const unresolvedBuildId = configuration?.version || revisions_js_1.PUPPETEER_REVISIONS[browser] || 'latest'; | ||
const baseUrl = configuration?.downloadBaseUrl; | ||
const buildId = await (0, browsers_1.resolveBuildId)(browser, platform, unresolvedBuildId); | ||
try { | ||
const result = await (0, browsers_1.install)({ | ||
browser, | ||
cacheDir, | ||
platform, | ||
buildId, | ||
downloadProgressCallback: (0, browsers_1.makeProgressCallback)(browser, buildId), | ||
baseUrl, | ||
buildIdAlias: buildId !== unresolvedBuildId ? unresolvedBuildId : undefined, | ||
}); | ||
logPolitely(`${browser} (${result.buildId}) downloaded to ${result.path}`); | ||
} | ||
catch (error) { | ||
throw new Error(`ERROR: Failed to set up ${browser} v${buildId}! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.`, { | ||
cause: error, | ||
}); | ||
} | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
const supportedProducts = { | ||
chrome: 'Chrome', | ||
firefox: 'Firefox Nightly', | ||
}; | ||
/** | ||
* @internal | ||
*/ | ||
async function downloadBrowser() { | ||
async function downloadBrowsers() { | ||
overrideProxy(); | ||
const configuration = (0, getConfiguration_js_1.getConfiguration)(); | ||
if (configuration.skipDownload) { | ||
logPolitely('**INFO** Skipping browser download as instructed.'); | ||
logPolitely('**INFO** Skipping downloading browsers as instructed.'); | ||
return; | ||
} | ||
const downloadBaseUrl = configuration.downloadBaseUrl; | ||
const platform = (0, browsers_1.detectBrowserPlatform)(); | ||
@@ -35,61 +49,41 @@ if (!platform) { | ||
} | ||
const product = configuration.defaultProduct; | ||
const browser = productToBrowser(product); | ||
const unresolvedBuildId = configuration.browserRevision || revisions_js_1.PUPPETEER_REVISIONS[product] || 'latest'; | ||
const unresolvedShellBuildId = configuration.browserRevision || | ||
revisions_js_1.PUPPETEER_REVISIONS['chrome-headless-shell'] || | ||
'latest'; | ||
const cacheDir = configuration.cacheDirectory; | ||
const installationJobs = []; | ||
if (configuration.chrome?.skipDownload) { | ||
logPolitely('**INFO** Skipping Chrome download as instructed.'); | ||
} | ||
else { | ||
const browser = browsers_1.Browser.CHROME; | ||
installationJobs.push(downloadBrowser({ | ||
browser, | ||
configuration: configuration[browser] ?? {}, | ||
cacheDir, | ||
platform, | ||
})); | ||
} | ||
if (configuration['chrome-headless-shell']?.skipDownload) { | ||
logPolitely('**INFO** Skipping Chrome download as instructed.'); | ||
} | ||
else { | ||
const browser = browsers_1.Browser.CHROMEHEADLESSSHELL; | ||
installationJobs.push(downloadBrowser({ | ||
browser, | ||
configuration: configuration[browser] ?? {}, | ||
cacheDir, | ||
platform, | ||
})); | ||
} | ||
if (configuration.firefox?.skipDownload) { | ||
logPolitely('**INFO** Skipping Firefox download as instructed.'); | ||
} | ||
else { | ||
const browser = browsers_1.Browser.FIREFOX; | ||
installationJobs.push(downloadBrowser({ | ||
browser, | ||
configuration: configuration[browser] ?? {}, | ||
cacheDir, | ||
platform, | ||
})); | ||
} | ||
try { | ||
const installationJobs = []; | ||
if (configuration.skipChromeDownload) { | ||
logPolitely('**INFO** Skipping Chrome download as instructed.'); | ||
} | ||
else { | ||
const buildId = await (0, browsers_1.resolveBuildId)(browser, platform, unresolvedBuildId); | ||
installationJobs.push((0, browsers_1.install)({ | ||
browser, | ||
cacheDir, | ||
platform, | ||
buildId, | ||
downloadProgressCallback: (0, browsers_1.makeProgressCallback)(browser, buildId), | ||
baseUrl: downloadBaseUrl, | ||
buildIdAlias: buildId !== unresolvedBuildId ? unresolvedBuildId : undefined, | ||
}) | ||
.then(result => { | ||
logPolitely(`${supportedProducts[product]} (${result.buildId}) downloaded to ${result.path}`); | ||
}) | ||
.catch(error => { | ||
throw new Error(`ERROR: Failed to set up ${supportedProducts[product]} v${buildId}! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.`, { | ||
cause: error, | ||
}); | ||
})); | ||
} | ||
if (browser === browsers_1.Browser.CHROME) { | ||
if (configuration.skipChromeHeadlessShellDownload) { | ||
logPolitely('**INFO** Skipping Chrome download as instructed.'); | ||
} | ||
else { | ||
const shellBuildId = await (0, browsers_1.resolveBuildId)(browser, platform, unresolvedShellBuildId); | ||
installationJobs.push((0, browsers_1.install)({ | ||
browser: browsers_1.Browser.CHROMEHEADLESSSHELL, | ||
cacheDir, | ||
platform, | ||
buildId: shellBuildId, | ||
downloadProgressCallback: (0, browsers_1.makeProgressCallback)(browsers_1.Browser.CHROMEHEADLESSSHELL, shellBuildId), | ||
baseUrl: downloadBaseUrl, | ||
buildIdAlias: shellBuildId !== unresolvedShellBuildId | ||
? unresolvedShellBuildId | ||
: undefined, | ||
}) | ||
.then(result => { | ||
logPolitely(`${browsers_1.Browser.CHROMEHEADLESSSHELL} (${result.buildId}) downloaded to ${result.path}`); | ||
}) | ||
.catch(error => { | ||
throw new Error(`ERROR: Failed to set up ${browsers_1.Browser.CHROMEHEADLESSSHELL} v${shellBuildId}! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.`, { | ||
cause: error, | ||
}); | ||
})); | ||
} | ||
} | ||
await Promise.all(installationJobs); | ||
@@ -102,12 +96,3 @@ } | ||
} | ||
exports.downloadBrowser = downloadBrowser; | ||
function productToBrowser(product) { | ||
switch (product) { | ||
case 'chrome': | ||
return browsers_1.Browser.CHROME; | ||
case 'firefox': | ||
return browsers_1.Browser.FIREFOX; | ||
} | ||
return browsers_1.Browser.CHROME; | ||
} | ||
exports.downloadBrowsers = downloadBrowsers; | ||
/** | ||
@@ -114,0 +99,0 @@ * @internal |
@@ -27,3 +27,3 @@ /** | ||
*/ | ||
function isSupportedProduct(product) { | ||
function isSupportedBrowser(product) { | ||
switch (product) { | ||
@@ -40,2 +40,53 @@ case 'chrome': | ||
*/ | ||
function getDefaultBrowser(browser) { | ||
// Validate configuration. | ||
if (browser && !isSupportedBrowser(browser)) { | ||
throw new Error(`Unsupported browser ${browser}`); | ||
} | ||
switch (browser) { | ||
case 'firefox': | ||
return 'firefox'; | ||
default: | ||
return 'chrome'; | ||
} | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
function getLogLevel(logLevel) { | ||
switch (logLevel) { | ||
case 'silent': | ||
return 'silent'; | ||
case 'error': | ||
return 'error'; | ||
default: | ||
return 'warn'; | ||
} | ||
} | ||
function getBrowserSetting(browser, configuration, defaultConfig = {}) { | ||
if (configuration.skipDownload) { | ||
return { | ||
skipDownload: true, | ||
}; | ||
} | ||
const browserSetting = {}; | ||
const browserEnvName = browser.replaceAll('-', '_').toUpperCase(); | ||
browserSetting.version = | ||
process.env[`PUPPETEER_${browserEnvName}_VERSION`] ?? | ||
configuration[browser]?.version ?? | ||
defaultConfig.version; | ||
browserSetting.downloadBaseUrl = | ||
process.env[`PUPPETEER_${browserEnvName}_DOWNLOAD_BASE_URL`] ?? | ||
configuration[browser]?.downloadBaseUrl ?? | ||
defaultConfig.downloadBaseUrl; | ||
browserSetting.skipDownload = | ||
getBooleanEnvVar(`PUPPETEER_${browserEnvName}_SKIP_DOWNLOAD`) ?? | ||
getBooleanEnvVar(`PUPPETEER_SKIP_${browserEnvName}_DOWNLOAD`) ?? | ||
configuration[browser]?.skipDownload ?? | ||
defaultConfig.skipDownload; | ||
return browserSetting; | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
export const getConfiguration = () => { | ||
@@ -46,18 +97,7 @@ const result = cosmiconfigSync('puppeteer', { | ||
const configuration = result ? result.config : {}; | ||
configuration.logLevel = (process.env['PUPPETEER_LOGLEVEL'] ?? | ||
process.env['npm_config_LOGLEVEL'] ?? | ||
process.env['npm_package_config_LOGLEVEL'] ?? | ||
configuration.logLevel ?? | ||
'warn'); | ||
configuration.logLevel = getLogLevel(process.env['PUPPETEER_LOGLEVEL'] ?? configuration.logLevel); | ||
// Merging environment variables. | ||
configuration.defaultProduct = (process.env['PUPPETEER_PRODUCT'] ?? | ||
process.env['npm_config_puppeteer_product'] ?? | ||
process.env['npm_package_config_puppeteer_product'] ?? | ||
configuration.defaultProduct ?? | ||
'chrome'); | ||
configuration.defaultBrowser = getDefaultBrowser(process.env['PUPPETEER_BROWSER'] ?? configuration.defaultBrowser); | ||
configuration.executablePath = | ||
process.env['PUPPETEER_EXECUTABLE_PATH'] ?? | ||
process.env['npm_config_puppeteer_executable_path'] ?? | ||
process.env['npm_package_config_puppeteer_executable_path'] ?? | ||
configuration.executablePath; | ||
process.env['PUPPETEER_EXECUTABLE_PATH'] ?? configuration.executablePath; | ||
// Default to skipDownload if executablePath is set | ||
@@ -68,60 +108,19 @@ if (configuration.executablePath) { | ||
// Set skipDownload explicitly or from default | ||
configuration.skipDownload = Boolean(getBooleanEnvVar('PUPPETEER_SKIP_DOWNLOAD') ?? | ||
getBooleanEnvVar('npm_config_puppeteer_skip_download') ?? | ||
getBooleanEnvVar('npm_package_config_puppeteer_skip_download') ?? | ||
configuration.skipDownload); | ||
// Set skipChromeDownload explicitly or from default | ||
configuration.skipChromeDownload = Boolean(getBooleanEnvVar('PUPPETEER_SKIP_CHROME_DOWNLOAD') ?? | ||
getBooleanEnvVar('npm_config_puppeteer_skip_chrome_download') ?? | ||
getBooleanEnvVar('npm_package_config_puppeteer_skip_chrome_download') ?? | ||
configuration.skipChromeDownload); | ||
// Set skipChromeDownload explicitly or from default | ||
configuration.skipChromeHeadlessShellDownload = Boolean(getBooleanEnvVar('PUPPETEER_SKIP_CHROME_HEADLESS_SHELL_DOWNLOAD') ?? | ||
getBooleanEnvVar('npm_config_puppeteer_skip_chrome_headless_shell_download') ?? | ||
getBooleanEnvVar('npm_package_config_puppeteer_skip_chrome_headless_shell_download') ?? | ||
configuration.skipChromeHeadlessShellDownload); | ||
configuration.skipDownload = | ||
getBooleanEnvVar('PUPPETEER_SKIP_DOWNLOAD') ?? configuration.skipDownload; | ||
// Prepare variables used in browser downloading | ||
if (!configuration.skipDownload) { | ||
configuration.browserRevision = | ||
process.env['PUPPETEER_BROWSER_REVISION'] ?? | ||
process.env['npm_config_puppeteer_browser_revision'] ?? | ||
process.env['npm_package_config_puppeteer_browser_revision'] ?? | ||
configuration.browserRevision; | ||
const downloadHost = process.env['PUPPETEER_DOWNLOAD_HOST'] ?? | ||
process.env['npm_config_puppeteer_download_host'] ?? | ||
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; | ||
} | ||
if (Object.keys(process.env).some(key => { | ||
return key.startsWith('npm_package_config_puppeteer_'); | ||
}) && | ||
configuration.logLevel === 'warn') { | ||
console.warn(`Configuring Puppeteer via npm/package.json is deprecated. Use https://pptr.dev/guides/configuration instead.`); | ||
} | ||
configuration.chrome = getBrowserSetting('chrome', configuration); | ||
configuration['chrome-headless-shell'] = getBrowserSetting('chrome-headless-shell', configuration); | ||
configuration.firefox = getBrowserSetting('firefox', configuration, { | ||
skipDownload: true, | ||
}); | ||
configuration.cacheDirectory = | ||
process.env['PUPPETEER_CACHE_DIR'] ?? | ||
process.env['npm_config_puppeteer_cache_dir'] ?? | ||
process.env['npm_package_config_puppeteer_cache_dir'] ?? | ||
configuration.cacheDirectory ?? | ||
join(homedir(), '.cache', 'puppeteer'); | ||
configuration.temporaryDirectory = | ||
process.env['PUPPETEER_TMP_DIR'] ?? | ||
process.env['npm_config_puppeteer_tmp_dir'] ?? | ||
process.env['npm_package_config_puppeteer_tmp_dir'] ?? | ||
configuration.temporaryDirectory; | ||
process.env['PUPPETEER_TMP_DIR'] ?? configuration.temporaryDirectory; | ||
configuration.experiments ??= {}; | ||
// Validate configuration. | ||
if (!isSupportedProduct(configuration.defaultProduct)) { | ||
throw new Error(`Unsupported product ${configuration.defaultProduct}`); | ||
} | ||
return configuration; | ||
}; | ||
//# sourceMappingURL=getConfiguration.js.map |
@@ -21,18 +21,18 @@ #!/usr/bin/env node | ||
[Browser.CHROME]: { | ||
buildId: puppeteer.configuration.browserRevision || | ||
buildId: puppeteer.configuration.chrome?.version || | ||
PUPPETEER_REVISIONS['chrome'] || | ||
'latest', | ||
skipDownload: puppeteer.configuration.skipChromeDownload ?? false, | ||
skipDownload: puppeteer.configuration.chrome?.skipDownload ?? false, | ||
}, | ||
[Browser.FIREFOX]: { | ||
buildId: puppeteer.configuration.browserRevision || | ||
buildId: puppeteer.configuration.firefox?.version || | ||
PUPPETEER_REVISIONS['firefox'] || | ||
'latest', | ||
skipDownload: true, | ||
skipDownload: puppeteer.configuration.firefox?.skipDownload ?? true, | ||
}, | ||
[Browser.CHROMEHEADLESSSHELL]: { | ||
buildId: puppeteer.configuration.browserRevision || | ||
PUPPETEER_REVISIONS['chrome'] || | ||
buildId: puppeteer.configuration['chrome-headless-shell']?.version || | ||
PUPPETEER_REVISIONS['chrome-headless-shell'] || | ||
'latest', | ||
skipDownload: puppeteer.configuration.skipChromeHeadlessShellDownload ?? false, | ||
skipDownload: puppeteer.configuration['chrome-headless-shell']?.skipDownload ?? false, | ||
}, | ||
@@ -39,0 +39,0 @@ }, |
@@ -9,3 +9,3 @@ /** | ||
*/ | ||
export declare function downloadBrowser(): Promise<void>; | ||
export declare function downloadBrowsers(): Promise<void>; | ||
//# sourceMappingURL=install.d.ts.map |
@@ -9,20 +9,34 @@ /** | ||
import { getConfiguration } from '../getConfiguration.js'; | ||
async function downloadBrowser({ browser, configuration, cacheDir, platform, }) { | ||
const unresolvedBuildId = configuration?.version || PUPPETEER_REVISIONS[browser] || 'latest'; | ||
const baseUrl = configuration?.downloadBaseUrl; | ||
const buildId = await resolveBuildId(browser, platform, unresolvedBuildId); | ||
try { | ||
const result = await install({ | ||
browser, | ||
cacheDir, | ||
platform, | ||
buildId, | ||
downloadProgressCallback: makeProgressCallback(browser, buildId), | ||
baseUrl, | ||
buildIdAlias: buildId !== unresolvedBuildId ? unresolvedBuildId : undefined, | ||
}); | ||
logPolitely(`${browser} (${result.buildId}) downloaded to ${result.path}`); | ||
} | ||
catch (error) { | ||
throw new Error(`ERROR: Failed to set up ${browser} v${buildId}! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.`, { | ||
cause: error, | ||
}); | ||
} | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
const supportedProducts = { | ||
chrome: 'Chrome', | ||
firefox: 'Firefox Nightly', | ||
}; | ||
/** | ||
* @internal | ||
*/ | ||
export async function downloadBrowser() { | ||
export async function downloadBrowsers() { | ||
overrideProxy(); | ||
const configuration = getConfiguration(); | ||
if (configuration.skipDownload) { | ||
logPolitely('**INFO** Skipping browser download as instructed.'); | ||
logPolitely('**INFO** Skipping downloading browsers as instructed.'); | ||
return; | ||
} | ||
const downloadBaseUrl = configuration.downloadBaseUrl; | ||
const platform = detectBrowserPlatform(); | ||
@@ -32,61 +46,41 @@ if (!platform) { | ||
} | ||
const product = configuration.defaultProduct; | ||
const browser = productToBrowser(product); | ||
const unresolvedBuildId = configuration.browserRevision || PUPPETEER_REVISIONS[product] || 'latest'; | ||
const unresolvedShellBuildId = configuration.browserRevision || | ||
PUPPETEER_REVISIONS['chrome-headless-shell'] || | ||
'latest'; | ||
const cacheDir = configuration.cacheDirectory; | ||
const installationJobs = []; | ||
if (configuration.chrome?.skipDownload) { | ||
logPolitely('**INFO** Skipping Chrome download as instructed.'); | ||
} | ||
else { | ||
const browser = Browser.CHROME; | ||
installationJobs.push(downloadBrowser({ | ||
browser, | ||
configuration: configuration[browser] ?? {}, | ||
cacheDir, | ||
platform, | ||
})); | ||
} | ||
if (configuration['chrome-headless-shell']?.skipDownload) { | ||
logPolitely('**INFO** Skipping Chrome download as instructed.'); | ||
} | ||
else { | ||
const browser = Browser.CHROMEHEADLESSSHELL; | ||
installationJobs.push(downloadBrowser({ | ||
browser, | ||
configuration: configuration[browser] ?? {}, | ||
cacheDir, | ||
platform, | ||
})); | ||
} | ||
if (configuration.firefox?.skipDownload) { | ||
logPolitely('**INFO** Skipping Firefox download as instructed.'); | ||
} | ||
else { | ||
const browser = Browser.FIREFOX; | ||
installationJobs.push(downloadBrowser({ | ||
browser, | ||
configuration: configuration[browser] ?? {}, | ||
cacheDir, | ||
platform, | ||
})); | ||
} | ||
try { | ||
const installationJobs = []; | ||
if (configuration.skipChromeDownload) { | ||
logPolitely('**INFO** Skipping Chrome download as instructed.'); | ||
} | ||
else { | ||
const buildId = await resolveBuildId(browser, platform, unresolvedBuildId); | ||
installationJobs.push(install({ | ||
browser, | ||
cacheDir, | ||
platform, | ||
buildId, | ||
downloadProgressCallback: makeProgressCallback(browser, buildId), | ||
baseUrl: downloadBaseUrl, | ||
buildIdAlias: buildId !== unresolvedBuildId ? unresolvedBuildId : undefined, | ||
}) | ||
.then(result => { | ||
logPolitely(`${supportedProducts[product]} (${result.buildId}) downloaded to ${result.path}`); | ||
}) | ||
.catch(error => { | ||
throw new Error(`ERROR: Failed to set up ${supportedProducts[product]} v${buildId}! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.`, { | ||
cause: error, | ||
}); | ||
})); | ||
} | ||
if (browser === Browser.CHROME) { | ||
if (configuration.skipChromeHeadlessShellDownload) { | ||
logPolitely('**INFO** Skipping Chrome download as instructed.'); | ||
} | ||
else { | ||
const shellBuildId = await resolveBuildId(browser, platform, unresolvedShellBuildId); | ||
installationJobs.push(install({ | ||
browser: Browser.CHROMEHEADLESSSHELL, | ||
cacheDir, | ||
platform, | ||
buildId: shellBuildId, | ||
downloadProgressCallback: makeProgressCallback(Browser.CHROMEHEADLESSSHELL, shellBuildId), | ||
baseUrl: downloadBaseUrl, | ||
buildIdAlias: shellBuildId !== unresolvedShellBuildId | ||
? unresolvedShellBuildId | ||
: undefined, | ||
}) | ||
.then(result => { | ||
logPolitely(`${Browser.CHROMEHEADLESSSHELL} (${result.buildId}) downloaded to ${result.path}`); | ||
}) | ||
.catch(error => { | ||
throw new Error(`ERROR: Failed to set up ${Browser.CHROMEHEADLESSSHELL} v${shellBuildId}! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.`, { | ||
cause: error, | ||
}); | ||
})); | ||
} | ||
} | ||
await Promise.all(installationJobs); | ||
@@ -99,11 +93,2 @@ } | ||
} | ||
function productToBrowser(product) { | ||
switch (product) { | ||
case 'chrome': | ||
return Browser.CHROME; | ||
case 'firefox': | ||
return Browser.FIREFOX; | ||
} | ||
return Browser.CHROME; | ||
} | ||
/** | ||
@@ -110,0 +95,0 @@ * @internal |
{ | ||
"name": "puppeteer", | ||
"version": "22.15.0", | ||
"version": "23.0.0", | ||
"description": "A high-level API to control headless Chrome over the DevTools Protocol", | ||
@@ -126,4 +126,5 @@ "keywords": [ | ||
"dependencies": { | ||
"chromium-bidi": "0.6.4", | ||
"cosmiconfig": "^9.0.0", | ||
"puppeteer-core": "22.15.0", | ||
"puppeteer-core": "23.0.0", | ||
"@puppeteer/browsers": "2.3.0", | ||
@@ -130,0 +131,0 @@ "devtools-protocol": "0.0.1312386" |
@@ -8,7 +8,6 @@ # Puppeteer | ||
> Puppeteer is a Node.js library which provides a high-level API to control | ||
> Puppeteer is a JavaScript library which provides a high-level API to control | ||
> Chrome or Firefox over the | ||
> [DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) or [WebDriver BiDi](https://pptr.dev/webdriver-bidi). | ||
> Puppeteer runs in the headless (no visible UI) by default | ||
> but can be configured to run in a visible ("headful") browser. | ||
@@ -15,0 +14,0 @@ ## [Get started](https://pptr.dev/docs) | [API](https://pptr.dev/api) | [FAQ](https://pptr.dev/faq) | [Contributing](https://pptr.dev/contributing) | [Troubleshooting](https://pptr.dev/troubleshooting) |
@@ -11,5 +11,11 @@ /** | ||
import {cosmiconfigSync} from 'cosmiconfig'; | ||
import type {Configuration, Product} from 'puppeteer-core'; | ||
import type { | ||
ChromeHeadlessShellSettings, | ||
ChromeSettings, | ||
Configuration, | ||
FirefoxSettings, | ||
SupportedBrowser, | ||
} from 'puppeteer-core'; | ||
function getBooleanEnvVar(name: string) { | ||
function getBooleanEnvVar(name: string): boolean | undefined { | ||
const env = process.env[name]; | ||
@@ -33,3 +39,3 @@ if (env === undefined) { | ||
*/ | ||
function isSupportedProduct(product: unknown): product is Product { | ||
function isSupportedBrowser(product: unknown): product is SupportedBrowser { | ||
switch (product) { | ||
@@ -47,2 +53,69 @@ case 'chrome': | ||
*/ | ||
function getDefaultBrowser(browser: unknown): SupportedBrowser { | ||
// Validate configuration. | ||
if (browser && !isSupportedBrowser(browser)) { | ||
throw new Error(`Unsupported browser ${browser}`); | ||
} | ||
switch (browser) { | ||
case 'firefox': | ||
return 'firefox'; | ||
default: | ||
return 'chrome'; | ||
} | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
function getLogLevel(logLevel: unknown): 'silent' | 'error' | 'warn' { | ||
switch (logLevel) { | ||
case 'silent': | ||
return 'silent'; | ||
case 'error': | ||
return 'error'; | ||
default: | ||
return 'warn'; | ||
} | ||
} | ||
function getBrowserSetting( | ||
browser: 'chrome' | 'chrome-headless-shell' | 'firefox', | ||
configuration: Configuration, | ||
defaultConfig: | ||
| ChromeSettings | ||
| ChromeHeadlessShellSettings | ||
| FirefoxSettings = {} | ||
): ChromeSettings | ChromeHeadlessShellSettings | FirefoxSettings { | ||
if (configuration.skipDownload) { | ||
return { | ||
skipDownload: true, | ||
}; | ||
} | ||
const browserSetting: | ||
| ChromeSettings | ||
| ChromeHeadlessShellSettings | ||
| FirefoxSettings = {}; | ||
const browserEnvName = browser.replaceAll('-', '_').toUpperCase(); | ||
browserSetting.version = | ||
process.env[`PUPPETEER_${browserEnvName}_VERSION`] ?? | ||
configuration[browser]?.version ?? | ||
defaultConfig.version; | ||
browserSetting.downloadBaseUrl = | ||
process.env[`PUPPETEER_${browserEnvName}_DOWNLOAD_BASE_URL`] ?? | ||
configuration[browser]?.downloadBaseUrl ?? | ||
defaultConfig.downloadBaseUrl; | ||
browserSetting.skipDownload = | ||
getBooleanEnvVar(`PUPPETEER_${browserEnvName}_SKIP_DOWNLOAD`) ?? | ||
getBooleanEnvVar(`PUPPETEER_SKIP_${browserEnvName}_DOWNLOAD`) ?? | ||
configuration[browser]?.skipDownload ?? | ||
defaultConfig.skipDownload; | ||
return browserSetting; | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
export const getConfiguration = (): Configuration => { | ||
@@ -54,20 +127,13 @@ const result = cosmiconfigSync('puppeteer', { | ||
configuration.logLevel = (process.env['PUPPETEER_LOGLEVEL'] ?? | ||
process.env['npm_config_LOGLEVEL'] ?? | ||
process.env['npm_package_config_LOGLEVEL'] ?? | ||
configuration.logLevel ?? | ||
'warn') as 'silent' | 'error' | 'warn'; | ||
configuration.logLevel = getLogLevel( | ||
process.env['PUPPETEER_LOGLEVEL'] ?? configuration.logLevel | ||
); | ||
// Merging environment variables. | ||
configuration.defaultProduct = (process.env['PUPPETEER_PRODUCT'] ?? | ||
process.env['npm_config_puppeteer_product'] ?? | ||
process.env['npm_package_config_puppeteer_product'] ?? | ||
configuration.defaultProduct ?? | ||
'chrome') as Product; | ||
configuration.defaultBrowser = getDefaultBrowser( | ||
process.env['PUPPETEER_BROWSER'] ?? configuration.defaultBrowser | ||
); | ||
configuration.executablePath = | ||
process.env['PUPPETEER_EXECUTABLE_PATH'] ?? | ||
process.env['npm_config_puppeteer_executable_path'] ?? | ||
process.env['npm_package_config_puppeteer_executable_path'] ?? | ||
configuration.executablePath; | ||
process.env['PUPPETEER_EXECUTABLE_PATH'] ?? configuration.executablePath; | ||
@@ -80,87 +146,26 @@ // Default to skipDownload if executablePath is set | ||
// Set skipDownload explicitly or from default | ||
configuration.skipDownload = Boolean( | ||
getBooleanEnvVar('PUPPETEER_SKIP_DOWNLOAD') ?? | ||
getBooleanEnvVar('npm_config_puppeteer_skip_download') ?? | ||
getBooleanEnvVar('npm_package_config_puppeteer_skip_download') ?? | ||
configuration.skipDownload | ||
); | ||
configuration.skipDownload = | ||
getBooleanEnvVar('PUPPETEER_SKIP_DOWNLOAD') ?? configuration.skipDownload; | ||
// Set skipChromeDownload explicitly or from default | ||
configuration.skipChromeDownload = Boolean( | ||
getBooleanEnvVar('PUPPETEER_SKIP_CHROME_DOWNLOAD') ?? | ||
getBooleanEnvVar('npm_config_puppeteer_skip_chrome_download') ?? | ||
getBooleanEnvVar('npm_package_config_puppeteer_skip_chrome_download') ?? | ||
configuration.skipChromeDownload | ||
// Prepare variables used in browser downloading | ||
configuration.chrome = getBrowserSetting('chrome', configuration); | ||
configuration['chrome-headless-shell'] = getBrowserSetting( | ||
'chrome-headless-shell', | ||
configuration | ||
); | ||
configuration.firefox = getBrowserSetting('firefox', configuration, { | ||
skipDownload: true, | ||
}); | ||
// Set skipChromeDownload explicitly or from default | ||
configuration.skipChromeHeadlessShellDownload = Boolean( | ||
getBooleanEnvVar('PUPPETEER_SKIP_CHROME_HEADLESS_SHELL_DOWNLOAD') ?? | ||
getBooleanEnvVar( | ||
'npm_config_puppeteer_skip_chrome_headless_shell_download' | ||
) ?? | ||
getBooleanEnvVar( | ||
'npm_package_config_puppeteer_skip_chrome_headless_shell_download' | ||
) ?? | ||
configuration.skipChromeHeadlessShellDownload | ||
); | ||
// Prepare variables used in browser downloading | ||
if (!configuration.skipDownload) { | ||
configuration.browserRevision = | ||
process.env['PUPPETEER_BROWSER_REVISION'] ?? | ||
process.env['npm_config_puppeteer_browser_revision'] ?? | ||
process.env['npm_package_config_puppeteer_browser_revision'] ?? | ||
configuration.browserRevision; | ||
const downloadHost = | ||
process.env['PUPPETEER_DOWNLOAD_HOST'] ?? | ||
process.env['npm_config_puppeteer_download_host'] ?? | ||
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; | ||
} | ||
if ( | ||
Object.keys(process.env).some(key => { | ||
return key.startsWith('npm_package_config_puppeteer_'); | ||
}) && | ||
configuration.logLevel === 'warn' | ||
) { | ||
console.warn( | ||
`Configuring Puppeteer via npm/package.json is deprecated. Use https://pptr.dev/guides/configuration instead.` | ||
); | ||
} | ||
configuration.cacheDirectory = | ||
process.env['PUPPETEER_CACHE_DIR'] ?? | ||
process.env['npm_config_puppeteer_cache_dir'] ?? | ||
process.env['npm_package_config_puppeteer_cache_dir'] ?? | ||
configuration.cacheDirectory ?? | ||
join(homedir(), '.cache', 'puppeteer'); | ||
configuration.temporaryDirectory = | ||
process.env['PUPPETEER_TMP_DIR'] ?? | ||
process.env['npm_config_puppeteer_tmp_dir'] ?? | ||
process.env['npm_package_config_puppeteer_tmp_dir'] ?? | ||
configuration.temporaryDirectory; | ||
process.env['PUPPETEER_TMP_DIR'] ?? configuration.temporaryDirectory; | ||
configuration.experiments ??= {}; | ||
// Validate configuration. | ||
if (!isSupportedProduct(configuration.defaultProduct)) { | ||
throw new Error(`Unsupported product ${configuration.defaultProduct}`); | ||
} | ||
return configuration; | ||
}; |
@@ -27,23 +27,23 @@ #!/usr/bin/env node | ||
buildId: | ||
puppeteer.configuration.browserRevision || | ||
puppeteer.configuration.chrome?.version || | ||
PUPPETEER_REVISIONS['chrome'] || | ||
'latest', | ||
skipDownload: puppeteer.configuration.skipChromeDownload ?? false, | ||
skipDownload: puppeteer.configuration.chrome?.skipDownload ?? false, | ||
}, | ||
[Browser.FIREFOX]: { | ||
buildId: | ||
puppeteer.configuration.browserRevision || | ||
puppeteer.configuration.firefox?.version || | ||
PUPPETEER_REVISIONS['firefox'] || | ||
'latest', | ||
skipDownload: true, | ||
skipDownload: puppeteer.configuration.firefox?.skipDownload ?? true, | ||
}, | ||
[Browser.CHROMEHEADLESSSHELL]: { | ||
buildId: | ||
puppeteer.configuration.browserRevision || | ||
PUPPETEER_REVISIONS['chrome'] || | ||
puppeteer.configuration['chrome-headless-shell']?.version || | ||
PUPPETEER_REVISIONS['chrome-headless-shell'] || | ||
'latest', | ||
skipDownload: | ||
puppeteer.configuration.skipChromeHeadlessShellDownload ?? false, | ||
puppeteer.configuration['chrome-headless-shell']?.skipDownload ?? false, | ||
}, | ||
}, | ||
}).run(process.argv); |
@@ -7,2 +7,3 @@ /** | ||
import type {BrowserPlatform} from '@puppeteer/browsers'; | ||
import { | ||
@@ -15,3 +16,7 @@ install, | ||
} from '@puppeteer/browsers'; | ||
import type {Product} from 'puppeteer-core'; | ||
import type { | ||
ChromeHeadlessShellSettings, | ||
ChromeSettings, | ||
FirefoxSettings, | ||
} from 'puppeteer-core'; | ||
import {PUPPETEER_REVISIONS} from 'puppeteer-core/internal/revisions.js'; | ||
@@ -21,14 +26,47 @@ | ||
/** | ||
* @internal | ||
*/ | ||
const supportedProducts = { | ||
chrome: 'Chrome', | ||
firefox: 'Firefox Nightly', | ||
} as const; | ||
async function downloadBrowser({ | ||
browser, | ||
configuration, | ||
cacheDir, | ||
platform, | ||
}: { | ||
browser: Extract< | ||
Browser, | ||
Browser.CHROME | Browser.CHROMEHEADLESSSHELL | Browser.FIREFOX | ||
>; | ||
configuration: ChromeSettings | ChromeHeadlessShellSettings | FirefoxSettings; | ||
platform: BrowserPlatform; | ||
cacheDir: string; | ||
}) { | ||
const unresolvedBuildId = | ||
configuration?.version || PUPPETEER_REVISIONS[browser] || 'latest'; | ||
const baseUrl = configuration?.downloadBaseUrl; | ||
const buildId = await resolveBuildId(browser, platform, unresolvedBuildId); | ||
try { | ||
const result = await install({ | ||
browser, | ||
cacheDir, | ||
platform, | ||
buildId, | ||
downloadProgressCallback: makeProgressCallback(browser, buildId), | ||
baseUrl, | ||
buildIdAlias: | ||
buildId !== unresolvedBuildId ? unresolvedBuildId : undefined, | ||
}); | ||
logPolitely(`${browser} (${result.buildId}) downloaded to ${result.path}`); | ||
} catch (error) { | ||
throw new Error( | ||
`ERROR: Failed to set up ${browser} v${buildId}! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.`, | ||
{ | ||
cause: error, | ||
} | ||
); | ||
} | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
export async function downloadBrowser(): Promise<void> { | ||
export async function downloadBrowsers(): Promise<void> { | ||
overrideProxy(); | ||
@@ -38,8 +76,6 @@ | ||
if (configuration.skipDownload) { | ||
logPolitely('**INFO** Skipping browser download as instructed.'); | ||
logPolitely('**INFO** Skipping downloading browsers as instructed.'); | ||
return; | ||
} | ||
const downloadBaseUrl = configuration.downloadBaseUrl; | ||
const platform = detectBrowserPlatform(); | ||
@@ -49,96 +85,50 @@ if (!platform) { | ||
} | ||
const cacheDir = configuration.cacheDirectory!; | ||
const product = configuration.defaultProduct!; | ||
const browser = productToBrowser(product); | ||
const installationJobs = []; | ||
if (configuration.chrome?.skipDownload) { | ||
logPolitely('**INFO** Skipping Chrome download as instructed.'); | ||
} else { | ||
const browser = Browser.CHROME; | ||
installationJobs.push( | ||
downloadBrowser({ | ||
browser, | ||
configuration: configuration[browser] ?? {}, | ||
cacheDir, | ||
platform, | ||
}) | ||
); | ||
} | ||
const unresolvedBuildId = | ||
configuration.browserRevision || PUPPETEER_REVISIONS[product] || 'latest'; | ||
const unresolvedShellBuildId = | ||
configuration.browserRevision || | ||
PUPPETEER_REVISIONS['chrome-headless-shell'] || | ||
'latest'; | ||
if (configuration['chrome-headless-shell']?.skipDownload) { | ||
logPolitely('**INFO** Skipping Chrome download as instructed.'); | ||
} else { | ||
const browser = Browser.CHROMEHEADLESSSHELL; | ||
const cacheDir = configuration.cacheDirectory!; | ||
installationJobs.push( | ||
downloadBrowser({ | ||
browser, | ||
configuration: configuration[browser] ?? {}, | ||
cacheDir, | ||
platform, | ||
}) | ||
); | ||
} | ||
try { | ||
const installationJobs = []; | ||
if (configuration.firefox?.skipDownload) { | ||
logPolitely('**INFO** Skipping Firefox download as instructed.'); | ||
} else { | ||
const browser = Browser.FIREFOX; | ||
if (configuration.skipChromeDownload) { | ||
logPolitely('**INFO** Skipping Chrome download as instructed.'); | ||
} else { | ||
const buildId = await resolveBuildId( | ||
installationJobs.push( | ||
downloadBrowser({ | ||
browser, | ||
configuration: configuration[browser] ?? {}, | ||
cacheDir, | ||
platform, | ||
unresolvedBuildId | ||
); | ||
installationJobs.push( | ||
install({ | ||
browser, | ||
cacheDir, | ||
platform, | ||
buildId, | ||
downloadProgressCallback: makeProgressCallback(browser, buildId), | ||
baseUrl: downloadBaseUrl, | ||
buildIdAlias: | ||
buildId !== unresolvedBuildId ? unresolvedBuildId : undefined, | ||
}) | ||
.then(result => { | ||
logPolitely( | ||
`${supportedProducts[product]} (${result.buildId}) downloaded to ${result.path}` | ||
); | ||
}) | ||
.catch(error => { | ||
throw new Error( | ||
`ERROR: Failed to set up ${supportedProducts[product]} v${buildId}! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.`, | ||
{ | ||
cause: error, | ||
} | ||
); | ||
}) | ||
); | ||
} | ||
}) | ||
); | ||
} | ||
if (browser === Browser.CHROME) { | ||
if (configuration.skipChromeHeadlessShellDownload) { | ||
logPolitely('**INFO** Skipping Chrome download as instructed.'); | ||
} else { | ||
const shellBuildId = await resolveBuildId( | ||
browser, | ||
platform, | ||
unresolvedShellBuildId | ||
); | ||
installationJobs.push( | ||
install({ | ||
browser: Browser.CHROMEHEADLESSSHELL, | ||
cacheDir, | ||
platform, | ||
buildId: shellBuildId, | ||
downloadProgressCallback: makeProgressCallback( | ||
Browser.CHROMEHEADLESSSHELL, | ||
shellBuildId | ||
), | ||
baseUrl: downloadBaseUrl, | ||
buildIdAlias: | ||
shellBuildId !== unresolvedShellBuildId | ||
? unresolvedShellBuildId | ||
: undefined, | ||
}) | ||
.then(result => { | ||
logPolitely( | ||
`${Browser.CHROMEHEADLESSSHELL} (${result.buildId}) downloaded to ${result.path}` | ||
); | ||
}) | ||
.catch(error => { | ||
throw new Error( | ||
`ERROR: Failed to set up ${Browser.CHROMEHEADLESSSHELL} v${shellBuildId}! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.`, | ||
{ | ||
cause: error, | ||
} | ||
); | ||
}) | ||
); | ||
} | ||
} | ||
try { | ||
await Promise.all(installationJobs); | ||
@@ -151,12 +141,2 @@ } catch (error) { | ||
function productToBrowser(product?: Product) { | ||
switch (product) { | ||
case 'chrome': | ||
return Browser.CHROME; | ||
case 'firefox': | ||
return Browser.FIREFOX; | ||
} | ||
return Browser.CHROME; | ||
} | ||
/** | ||
@@ -163,0 +143,0 @@ * @internal |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 21 instances in 1 package
8818
34
342306
5
55
+ Addedchromium-bidi@0.6.4
+ Addedchromium-bidi@0.6.4(transitive)
+ Addedpuppeteer-core@23.0.0(transitive)
- Removedchromium-bidi@0.6.3(transitive)
- Removedpuppeteer-core@22.15.0(transitive)
Updatedpuppeteer-core@23.0.0