Fix NPM/Puppeteer error handling

main
Elbert Alias 5 years ago
parent 3c6dcf6afb
commit 945641654b

@ -62,7 +62,7 @@ class PuppeteerBrowser extends Browser {
let browser; let browser;
try { try {
await new Promise(async (resolve, _reject) => { await new Promise(async (resolve, reject) => {
try { try {
browser = await puppeteer.launch(chromium ? { browser = await puppeteer.launch(chromium ? {
args: [...chromium.args, '--ignore-certificate-errors'], args: [...chromium.args, '--ignore-certificate-errors'],
@ -70,13 +70,13 @@ class PuppeteerBrowser extends Browser {
executablePath: await chromium.executablePath, executablePath: await chromium.executablePath,
headless: chromium.headless, 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, executablePath: CHROME_BIN,
}); });
browser.on('disconnected', () => { browser.on('disconnected', () => {
if (!done) { 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.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) => { page.on('response', (response) => {
try { try {
@ -106,7 +106,7 @@ class PuppeteerBrowser extends Browser {
this.contentType = headers['content-type'] || null; this.contentType = headers['content-type'] || null;
} }
} catch (error) { } 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([ await Promise.race([
page.goto(url, { waitUntil: 'domcontentloaded' }), page.goto(url, { waitUntil: 'domcontentloaded' }),
new Promise(_resolve => setTimeout(() => { new Promise(_resolve => setTimeout(() => {
this.log('Timeout', 'error'); this.log('timeout', 'error');
_resolve(); _resolve();
}, this.options.maxWait)), }, this.options.maxWait)),
@ -156,21 +156,25 @@ class PuppeteerBrowser extends Browser {
resolve(); resolve();
} catch (error) { } catch (error) {
_reject(new Error(`visit error: ${error.message || error}`)); reject(new Error(`visit error: ${error.message || error}`));
} }
}); });
} catch (error) { } catch (error) {
this.log(`visit error: ${error.message || error}`, 'error');
throw new Error(error.message || error.toString());
} finally {
done = true; done = true;
if (browser) { if (browser) {
try { try {
await browser.close(); 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());
} }
} }
} }

@ -2,7 +2,7 @@
"name": "wappalyzer", "name": "wappalyzer",
"description": "Uncovers the technologies used on websites", "description": "Uncovers the technologies used on websites",
"homepage": "https://github.com/AliasIO/Wappalyzer", "homepage": "https://github.com/AliasIO/Wappalyzer",
"version": "5.9.22", "version": "5.9.23",
"author": "Elbert Alias", "author": "Elbert Alias",
"license": "GPL-3.0", "license": "GPL-3.0",
"repository": { "repository": {

@ -4,7 +4,7 @@
"author": "Elbert Alias", "author": "Elbert Alias",
"homepage_url": "https://www.wappalyzer.com", "homepage_url": "https://www.wappalyzer.com",
"description": "Identify web technologies", "description": "Identify web technologies",
"version": "5.9.22", "version": "5.9.23",
"default_locale": "en", "default_locale": "en",
"manifest_version": 2, "manifest_version": 2,
"icons": { "icons": {

Loading…
Cancel
Save