From 8dff69f2729fc0ee4fdf7055ec0f78999cd4f849 Mon Sep 17 00:00:00 2001 From: Elbert Alias <77259+AliasIO@users.noreply.github.com> Date: Sat, 11 Jun 2022 15:42:47 +1000 Subject: [PATCH] NPM fixes --- src/drivers/npm/driver.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/drivers/npm/driver.js b/src/drivers/npm/driver.js index 4d1ce77d7..b01706513 100644 --- a/src/drivers/npm/driver.js +++ b/src/drivers/npm/driver.js @@ -16,6 +16,8 @@ const chromiumArgs = [ '--no-sandbox', '--no-zygote', '--disable-gpu', + '--disable-software-rasterizer', + '--disable-features=AudioServiceOutOfProcess', '--ignore-certificate-errors', '--allow-running-insecure-content', '--disable-web-security', @@ -400,6 +402,8 @@ class Site { this.cache = {} this.probed = false + + this.destroyed = false } log(message, source = 'driver', type = 'log') { @@ -470,6 +474,10 @@ class Site { } async goto(url) { + if (this.destroyed) { + return + } + // Return when the URL is a duplicate or maxUrls has been reached if (this.analyzedUrls[url.href]) { return [] @@ -568,6 +576,10 @@ class Site { }) page.on('response', async (response) => { + if (this.destroyed || !page || page.isClosed()) { + return + } + try { if ( response.status() < 300 && @@ -578,7 +590,11 @@ class Site { await this.onDetect(response.url(), analyze({ scripts })) } + } catch (error) { + this.error(error) + } + try { if (response.url() === url.href) { this.analyzedUrls[url.href] = { status: response.status(), @@ -644,7 +660,7 @@ class Site { } if (page.url() === 'about:blank') { - throw new Error('The website failed to load') + throw new Error(`The page failed to load (${url.href})`) } if (!this.options.noScripts) { @@ -906,7 +922,11 @@ class Site { ...this.cache[url.href], }) - await page.close() + try { + await page.close() + } catch (error) { + // Continue + } this.log(`Page closed (${url})`) @@ -917,7 +937,7 @@ class Site { this.log(`Page closed (${url})`) } catch (error) { - this.log(error) + // Continue } let hostname = url @@ -1254,6 +1274,8 @@ class Site { }) ) + this.destroyed = true + this.log('Site closed') } }