From bd9a64e32fa04d28f7f9a69381ef87b28da2375f Mon Sep 17 00:00:00 2001 From: Jose Bolos Date: Mon, 24 May 2021 16:28:22 +0100 Subject: [PATCH] Retry launching browser if first time fails This is a first attempt at fixing #128. It's unlikely to fix the issue completely, or even at all, as the browser will sometimes crash after testing several URLs and we don't have any logic to reopen a browser that has crashed mid-tests. --- lib/pa11y-ci.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/pa11y-ci.js b/lib/pa11y-ci.js index 14888fa..41c9b7d 100644 --- a/lib/pa11y-ci.js +++ b/lib/pa11y-ci.js @@ -41,7 +41,22 @@ module.exports.defaults = { function pa11yCi(urls, options) { return new Promise(async resolve => { // Create a test browser to assign to tests - const testBrowser = await puppeteer.launch(options.chromeLaunchConfig); + let testBrowser; + + // Issue #128: on specific URLs, Chrome will sometimes fail to load + // the page, or crash during or after loading. This attempts to + // relaunch the browser just once before bailing out, in case Chrome + // crashed at startup. This is just an attempt at mitigating it, + // it won't fix #128 completely or even at all + try { + testBrowser = await puppeteer.launch( + options.chromeLaunchConfig + ); + } catch (error) { + testBrowser = await puppeteer.launch( + options.chromeLaunchConfig + ); + } // Default the passed in options options = defaults({}, options, module.exports.defaults); @@ -52,7 +67,6 @@ function pa11yCi(urls, options) { const log = options.log; delete options.log; - // Create a Pa11y test function and an async queue const taskQueue = queue(testRunner, options.concurrency); taskQueue.drain = testRunComplete;