libs/scully/src/lib/renderPlugins/launchedBrowser.js
/**
 * Helper to try launching pupteer, tries 3 times, and then exits on failure.
 * it also features an timeout, for when puppeteer silently fails
 * @param options Puppeteer launch options
 * @param failedLaunches number of retries.
 * @returns promise<Browser>
 */
Helper to try launching pupteer, tries 3 times, and then exits on failure.
it also features an timeout, for when puppeteer silently fails
@param options Puppeteer launch options
@param failedLaunches number of retries.
@returns promise
Helper to try launching pupteer tries 3 times and then exits on failure . it also features an timeout for when puppeteer silently fails @param options Puppeteer launch options @param failedLaunches number of retries . @returns promise
function launchPuppeteerWithRetry(options, failedLaunches = 0) {
    const timeout = (millisecs) => new Promise((_, reject) => setTimeout(() => reject('timeout'), millisecs));
    return Promise.race([
        timeout(Math.max( 60 * 1000)),
        launch(options).then((b) => {
            return b;
        }),
    ])
        .catch((e) => {
        if (e.message.includes('Could not find browser revision')) {
            throw new Error('Failed launch');
        }
        if (++failedLaunches < 3) {
            return launchPuppeteerWithRetry(options, failedLaunches);
        }
        throw new Error('failed 3 times to launch');
    })
        .catch((b) => {
        logError(`
=================================================================================================
Puppeteer cannot find or launch the browser. (by default chrome)
 Try adding 'puppeteerLaunchOptions: {executablePath: CHROMIUM_PATH}'
 to your scully.*.config.ts file.
Also, this might happen because the default timeout (60 seconds) is to short on this system
this can be fixed by adding the ${yellow('--serverTimeout=x')} cmd line option.
   (where x = the new timeout in milliseconds)
When this happens in CI/CD you can find some additional information here:
https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
=================================================================================================
      `);
        process.exit(15);
    });
}
function launchPuppeteerWithRetry ( options , failedLaunches = 0 ) { const timeout = ( millisecs ) => new Promise ( ( _ , reject ) => setTimeout ( ( ) => reject ( 'timeout' ) , millisecs ) ) ; return Promise . race ( [ timeout ( Math . max ( 60 * 1000 ) ) , launch ( options ) . then ( ( b ) => { return b ; } ) , ] ) . catch ( ( e ) => { if ( e . message . includes ( 'Could not find browser revision' ) ) { throw new Error ( 'Failed launch' ) ; } if ( ++ failedLaunches < 3 ) { return launchPuppeteerWithRetry ( options , failedLaunches ) ; } throw new Error ( 'failed 3 times to launch' ) ; } ) . catch ( ( b ) => { logError ( ` ${ yellow ( '--serverTimeout=x' ) } ` ) ; process . exit ( 15 ) ; } ) ; }
Helper to try launching pupteer, tries 3 times, and then exits on failure.
Helper to try launching pupteer tries 3 times and then exits on failure .
/** use a 1 minute timeout to detect a stalled launch of puppeteer */ /** serverTimeout,*/ /** first stage catch check for retry */ /** second stage catch, houston, we have a problem, and will abort */