Fix NPM/Puppeteer error handling

main
Elbert Alias 5 years ago
parent f522a2b549
commit 3c6dcf6afb

@ -57,11 +57,12 @@ class PuppeteerBrowser extends Browser {
super(options); super(options);
} }
visit(url) { async visit(url) {
return new Promise(async (resolve, reject) => {
let done = false; let done = false;
let browser; let browser;
try {
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'],
@ -75,7 +76,7 @@ class PuppeteerBrowser extends Browser {
browser.on('disconnected', () => { browser.on('disconnected', () => {
if (!done) { if (!done) {
reject(new Error('browser: disconnected')); _reject(new Error('browser: disconnected'));
} }
}); });
@ -83,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 {
@ -105,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}`));
} }
}); });
@ -155,19 +156,22 @@ 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}`));
} finally { }
});
} catch (error) {
done = true; done = true;
if (browser) { if (browser) {
try { try {
await browser.close(); await browser.close();
} catch (error) { } catch (_error) {
this.log(error.message || error.toString(), 'error'); this.log(_error.message || _error.toString(), '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.21", "version": "5.9.22",
"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.20", "version": "5.9.22",
"default_locale": "en", "default_locale": "en",
"manifest_version": 2, "manifest_version": 2,
"icons": { "icons": {

Loading…
Cancel
Save