diff --git a/src/BrowserFetcher.ts b/src/BrowserFetcher.ts index cfcb8567e1eed..f2fb815ba4cf6 100644 --- a/src/BrowserFetcher.ts +++ b/src/BrowserFetcher.ts @@ -321,10 +321,45 @@ function install(archivePath: string, folderPath: string): Promise { } async function extractZip(zipPath: string, folderPath: string): Promise { - try { - await extract(zipPath, {dir: folderPath}); - } catch (error) { - return error; + const nodeVersion = process.version; + + /* There is currently a bug with extract-zip and Node v14.0.0 that + * causes extractZip to silently fail: + * https://github.com/puppeteer/puppeteer/issues/5719 + * + * Rather than silenty fail if the user is on Node 14 we instead + * detect that and throw an error directing the user to that bug. The + * rejection message below is surfaced to the user in the command + * line. + * + * The issue seems to be in streams never resolving so we wrap the + * call in a timeout and give it 10s to resolve before deciding on + * an error. + * + * If the user is on Node < 14 we maintain the behaviour we had before + * this patch. + */ + if (nodeVersion.startsWith('v14.')) { + let timeoutReject; + const timeoutPromise = new Promise((resolve, reject) => { timeoutReject = reject; }); + + const timeoutToken = setTimeout(() => { + const error = new Error(`Puppeteer currently does not work on Node v14 due to an upstream bug. Please see: https://github.com/puppeteer/puppeteer/issues/5719 for details.`); + timeoutReject(error); + }, 10 * 1000); + + await Promise.race([ + extract(zipPath, {dir: folderPath}), + timeoutPromise + ]); + + clearTimeout(timeoutToken); + } else { + try { + await extract(zipPath, {dir: folderPath}); + } catch (error) { + return error; + } } }