Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function downloadChromium() {
const browserFetcher = puppeteer.createBrowserFetcher({
path: chromeTempPath,
host: downloadHost,
})
const revision =
process.env.PUPPETEER_CHROMIUM_REVISION ||
process.env.npm_config_puppeteer_chromium_revision ||
process.env.npm_package_config_puppeteer_chromium_revision ||
pptrCoreJson.puppeteer.chromium_revision
const revisionInfo = browserFetcher.revisionInfo(revision)
// If already downloaded
if (revisionInfo.local) return revisionInfo
try {
console.log(`Downloading Chromium r${revision}...`)
const newRevisionInfo = await browserFetcher.download(revisionInfo.revision)
console.log(`Chromium downloaded to ${newRevisionInfo.folderPath}`)
let localRevisions = await browserFetcher.localRevisions()
localRevisions = localRevisions.filter(r => r !== revisionInfo.revision)
// Remove previous revisions
const cleanupOldVersions = localRevisions.map(r => browserFetcher.remove(r))
await Promise.all(cleanupOldVersions)