From e9c57d1bbcab87a2de581cca35b133f54e323818 Mon Sep 17 00:00:00 2001 From: Wil Wilsman Date: Tue, 4 Aug 2020 13:12:44 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Ensure=20discoverer=20cleanup=20?= =?UTF-8?q?happens=20even=20when=20the=20page=20crashes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/discoverer.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/core/src/discoverer.js b/packages/core/src/discoverer.js index c75791c89..c3849cb90 100644 --- a/packages/core/src/discoverer.js +++ b/packages/core/src/discoverer.js @@ -131,15 +131,17 @@ export default class PercyDiscoverer { meta })); - // navigate to the root URL and wait for the network to idle - await page.goto(rootUrl); - await idle(() => processing, this.networkIdleTimeout); - - // cleanup - page.removeAllListeners('request'); - page.removeAllListeners('requestfailed'); - page.removeAllListeners('requestfinished'); - await page.close(); + try { + // navigate to the root URL and wait for the network to idle + await page.goto(rootUrl); + await idle(() => processing, this.networkIdleTimeout); + } finally { + // cleanup + page.removeAllListeners('request'); + page.removeAllListeners('requestfailed'); + page.removeAllListeners('requestfinished'); + await page.close(); + } }); }