From 8809ab664125711f6063d982d457f6203e552b65 Mon Sep 17 00:00:00 2001 From: Elbert Alias <77259+AliasIO@users.noreply.github.com> Date: Mon, 13 Jan 2020 13:48:00 +1100 Subject: [PATCH] Fix NPM+puppeteer disconnect error handling --- src/drivers/npm/browsers/puppeteer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/drivers/npm/browsers/puppeteer.js b/src/drivers/npm/browsers/puppeteer.js index e4a8b57e8..6a171b8fe 100644 --- a/src/drivers/npm/browsers/puppeteer.js +++ b/src/drivers/npm/browsers/puppeteer.js @@ -46,6 +46,7 @@ class PuppeteerBrowser extends Browser { } async visit(url) { + let done = false; let browser; try { @@ -55,7 +56,9 @@ class PuppeteerBrowser extends Browser { } browser.on('disconnected', () => { - throw new Error('Disconnected'); + if (!done) { + throw new Error('Disconnected'); + } }); try { @@ -133,6 +136,8 @@ class PuppeteerBrowser extends Browser { } catch (error) { throw new Error(error.message || error.toString()); } finally { + done = true; + await browser.close(); } }