From 945641654bf1eda80c07921b34164bb4fca48f85 Mon Sep 17 00:00:00 2001 From: Elbert Alias <77259+AliasIO@users.noreply.github.com> Date: Thu, 27 Feb 2020 15:58:23 +1100 Subject: [PATCH] Fix NPM/Puppeteer error handling --- src/drivers/npm/browsers/puppeteer.js | 26 +++++++++++++++----------- src/drivers/npm/package.json | 2 +- src/drivers/webextension/manifest.json | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/drivers/npm/browsers/puppeteer.js b/src/drivers/npm/browsers/puppeteer.js index efc70061d..ecde8faff 100644 --- a/src/drivers/npm/browsers/puppeteer.js +++ b/src/drivers/npm/browsers/puppeteer.js @@ -62,7 +62,7 @@ class PuppeteerBrowser extends Browser { let browser; try { - await new Promise(async (resolve, _reject) => { + await new Promise(async (resolve, reject) => { try { browser = await puppeteer.launch(chromium ? { args: [...chromium.args, '--ignore-certificate-errors'], @@ -70,13 +70,13 @@ class PuppeteerBrowser extends Browser { executablePath: await chromium.executablePath, headless: chromium.headless, } : { - args: ['--no-sandbox', '--headless', '--disable-gpu', '--ignore-certificate-errors', '--disable-dev-shm-usage'], + args: ['--no-sandbox', '--headless', '--disable-gpu', '--ignore-certificate-errors'], executablePath: CHROME_BIN, }); browser.on('disconnected', () => { if (!done) { - _reject(new Error('browser: disconnected')); + reject(new Error('browser: disconnected')); } }); @@ -84,7 +84,7 @@ class PuppeteerBrowser extends Browser { page.setDefaultTimeout(this.options.maxWait * 2); - page.on('error', error => _reject(new Error(`page error: ${error.message || error}`))); + page.on('error', error => reject(new Error(`page error: ${error.message || error}`))); page.on('response', (response) => { try { @@ -106,7 +106,7 @@ class PuppeteerBrowser extends Browser { this.contentType = headers['content-type'] || null; } } catch (error) { - _reject(new Error(`page error: ${error.message || error}`)); + reject(new Error(`page error: ${error.message || error}`)); } }); @@ -117,7 +117,7 @@ class PuppeteerBrowser extends Browser { await Promise.race([ page.goto(url, { waitUntil: 'domcontentloaded' }), new Promise(_resolve => setTimeout(() => { - this.log('Timeout', 'error'); + this.log('timeout', 'error'); _resolve(); }, this.options.maxWait)), @@ -156,21 +156,25 @@ class PuppeteerBrowser extends Browser { resolve(); } catch (error) { - _reject(new Error(`visit error: ${error.message || error}`)); + reject(new Error(`visit error: ${error.message || error}`)); } }); } catch (error) { + this.log(`visit error: ${error.message || error}`, 'error'); + + throw new Error(error.message || error.toString()); + } finally { done = true; if (browser) { try { await browser.close(); - } catch (_error) { - this.log(_error.message || _error.toString(), 'error'); + + this.log('browser close ok'); + } catch (error) { + this.log(`browser close error: ${error.message || error}`, 'error'); } } - - throw new Error(error.message || error.toString()); } } } diff --git a/src/drivers/npm/package.json b/src/drivers/npm/package.json index 64a29d62c..997407d48 100644 --- a/src/drivers/npm/package.json +++ b/src/drivers/npm/package.json @@ -2,7 +2,7 @@ "name": "wappalyzer", "description": "Uncovers the technologies used on websites", "homepage": "https://github.com/AliasIO/Wappalyzer", - "version": "5.9.22", + "version": "5.9.23", "author": "Elbert Alias", "license": "GPL-3.0", "repository": { diff --git a/src/drivers/webextension/manifest.json b/src/drivers/webextension/manifest.json index be890ceca..5d41a72c6 100644 --- a/src/drivers/webextension/manifest.json +++ b/src/drivers/webextension/manifest.json @@ -4,7 +4,7 @@ "author": "Elbert Alias", "homepage_url": "https://www.wappalyzer.com", "description": "Identify web technologies", - "version": "5.9.22", + "version": "5.9.23", "default_locale": "en", "manifest_version": 2, "icons": {