Fix stalling issue in NPM/Puppeteer, use default user agent

main
Elbert Alias 5 years ago
parent 80a25d81b9
commit 3134865c07

@ -82,7 +82,7 @@ class PuppeteerBrowser extends Browser {
const page = await browser.newPage(); const page = await browser.newPage();
page.setDefaultTimeout(this.options.maxWait * 2); page.setDefaultTimeout(this.options.maxWait * 1.1);
await page.setRequestInterception(true); await page.setRequestInterception(true);
@ -101,9 +101,13 @@ class PuppeteerBrowser extends Browser {
this.log(`abort navigation to ${request.url()}`); this.log(`abort navigation to ${request.url()}`);
request.abort('aborted'); request.abort('aborted');
} else if (!done) {
if (!['document', 'script'].includes(request.resourceType())) {
request.abort();
} else { } else {
request.continue(); request.continue();
} }
}
} catch (error) { } catch (error) {
reject(new Error(`page error: ${error.message || error}`)); reject(new Error(`page error: ${error.message || error}`));
} }
@ -133,20 +137,25 @@ class PuppeteerBrowser extends Browser {
} }
}); });
page.on('console', ({ _type, _text, _location }) => this.log(`${_text} (${_location.url}: ${_location.lineNumber})`, _type)); page.on('console', ({ _type, _text, _location }) => {
if (!/Failed to load resource: net::ERR_FAILED/.test(_text)) {
this.log(`${_text} (${_location.url}: ${_location.lineNumber})`, _type);
}
});
if (this.options.userAgent) {
await page.setUserAgent(this.options.userAgent); await page.setUserAgent(this.options.userAgent);
}
try { try {
await Promise.race([ await Promise.race([
page.goto(url, { waitUntil: 'domcontentloaded' }), page.goto(url, { waitUntil: 'domcontentloaded' }),
new Promise((_resolve, _reject) => setTimeout(() => _reject(new Error('timeout')), this.options.maxWait)), // eslint-disable-next-line no-shadow
new Promise((resolve, reject) => setTimeout(() => reject(new Error('timeout')), this.options.maxWait)),
]); ]);
} catch (error) { } catch (error) {
if (!this.statusCode) {
throw new Error(error.message || error.toString()); throw new Error(error.message || error.toString());
} }
}
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const links = await page.evaluateHandle(() => Array.from(document.getElementsByTagName('a')).map(({ const links = await page.evaluateHandle(() => Array.from(document.getElementsByTagName('a')).map(({
@ -185,7 +194,7 @@ class PuppeteerBrowser extends Browser {
} }
}); });
} catch (error) { } catch (error) {
this.log(`visit error: ${error.message || error}`, 'error'); this.log(`visit error: ${error.message || error} (${url})`, 'error');
throw new Error(error.message || error.toString()); throw new Error(error.message || error.toString());
} finally { } finally {
@ -201,6 +210,8 @@ class PuppeteerBrowser extends Browser {
} }
} }
} }
this.log(`visit ok (${url})`);
} }
} }

@ -79,7 +79,6 @@ class Driver {
maxUrls: 10, maxUrls: 10,
maxWait: 5000, maxWait: 5000,
recursive: false, recursive: false,
userAgent: 'Mozilla/5.0 (compatible; Wappalyzer)',
}, options || {}); }, options || {});
this.options.debug = Boolean(+this.options.debug); this.options.debug = Boolean(+this.options.debug);

@ -2,7 +2,7 @@
"name": "wappalyzer", "name": "wappalyzer",
"description": "Uncovers the technologies used on websites", "description": "Uncovers the technologies used on websites",
"homepage": "https://www.wappalyzer.com", "homepage": "https://www.wappalyzer.com",
"version": "5.9.30", "version": "5.9.31",
"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.30", "version": "5.9.31",
"default_locale": "en", "default_locale": "en",
"manifest_version": 2, "manifest_version": 2,
"icons": { "icons": {

Loading…
Cancel
Save