diff --git a/src/drivers/npm/browsers/puppeteer.js b/src/drivers/npm/browsers/puppeteer.js index c0266757b..8678b8b7b 100644 --- a/src/drivers/npm/browsers/puppeteer.js +++ b/src/drivers/npm/browsers/puppeteer.js @@ -68,100 +68,100 @@ class PuppeteerBrowser extends Browser { } async visit(url) { - let done = false; - let browser; + return new Promise(async (resolve, reject) => { + let done = false; + let browser; + + try { + browser = await this.browser(); + } catch (error) { + reject(new Error(error.message || error.toString())); + } - try { - browser = await this.browser(); - } catch (error) { - throw new Error(error.message || error.toString()); - } + browser.on('disconnected', () => { + if (!done) { + reject(new Error('Disconnected')); + } + }); - browser.on('disconnected', () => { - if (!done) { - throw new Error('Disconnected'); - } - }); + try { + const page = await browser.newPage(); - try { - const page = await browser.newPage(); + page.setDefaultTimeout(this.options.maxWait); - page.setDefaultTimeout(this.options.maxWait); + await page.setRequestInterception(true); - await page.setRequestInterception(true); + page.on('error', reject); - page.on('error', (error) => { - throw new Error(error.message || error.toString()); - }); + page.on('request', request => request.continue()); - page.on('request', request => request.continue()); + page.on('response', (response) => { + if (response.status() === 301 || response.status() === 302) { + return; + } - page.on('response', (response) => { - if (response.status() === 301 || response.status() === 302) { - return; - } + if (!this.statusCode) { + this.statusCode = response.status(); - if (!this.statusCode) { - this.statusCode = response.status(); + this.headers = {}; - this.headers = {}; + const headers = response.headers(); - const headers = response.headers(); + Object.keys(headers).forEach((key) => { + this.headers[key] = Array.isArray(headers[key]) ? headers[key] : [headers[key]]; + }); - Object.keys(headers).forEach((key) => { - this.headers[key] = Array.isArray(headers[key]) ? headers[key] : [headers[key]]; - }); + this.contentType = headers['content-type'] || null; + } + }); - this.contentType = headers['content-type'] || null; - } - }); + page.on('console', ({ _type, _text, _location }) => this.log(`${_text} (${_location.url}: ${_location.lineNumber})`, _type)); - page.on('console', ({ _type, _text, _location }) => this.log(`${_text} (${_location.url}: ${_location.lineNumber})`, _type)); + await page.setUserAgent(this.options.userAgent); - await page.setUserAgent(this.options.userAgent); + await Promise.race([ + page.goto(url, { waitUntil: 'networkidle2' }), + new Promise(_resolve => setTimeout(_resolve, this.options.maxWait)), + ]); - await Promise.race([ - page.goto(url, { waitUntil: 'networkidle2' }), - new Promise(resolve => setTimeout(resolve, this.options.maxWait)), - ]); + // eslint-disable-next-line no-undef + const links = await page.evaluateHandle(() => Array.from(document.getElementsByTagName('a')).map(({ + hash, hostname, href, pathname, protocol, rel, + }) => ({ + hash, + hostname, + href, + pathname, + protocol, + rel, + }))); - // eslint-disable-next-line no-undef - const links = await page.evaluateHandle(() => Array.from(document.getElementsByTagName('a')).map(({ - hash, hostname, href, pathname, protocol, rel, - }) => ({ - hash, - hostname, - href, - pathname, - protocol, - rel, - }))); - - this.links = await links.jsonValue(); + this.links = await links.jsonValue(); - // eslint-disable-next-line no-undef - const scripts = await page.evaluateHandle(() => Array.from(document.getElementsByTagName('script')).map(({ - src, - }) => src)); + // eslint-disable-next-line no-undef + const scripts = await page.evaluateHandle(() => Array.from(document.getElementsByTagName('script')).map(({ + src, + }) => src)); - this.scripts = (await scripts.jsonValue()).filter(script => script); + this.scripts = (await scripts.jsonValue()).filter(script => script); - this.js = await page.evaluate(getJs); + this.js = await page.evaluate(getJs); - this.cookies = (await page.cookies()).map(({ - name, value, domain, path, - }) => ({ - name, value, domain, path, - })); + this.cookies = (await page.cookies()).map(({ + name, value, domain, path, + }) => ({ + name, value, domain, path, + })); - this.html = await page.content(); - } catch (error) { - throw new Error(error.message || error.toString()); - } finally { - done = true; + this.html = await page.content(); + } catch (error) { + reject(error.message || error.toString()); + } finally { + done = true; - await browser.close(); - } + await browser.close(); + } + }); } } diff --git a/src/drivers/npm/package.json b/src/drivers/npm/package.json index d5705d0c4..0c48727b2 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.12", + "version": "5.9.13", "author": "Elbert Alias", "license": "GPL-3.0", "repository": { diff --git a/src/wappalyzer.js b/src/wappalyzer.js index 7a2c3e368..66d50d2b2 100644 --- a/src/wappalyzer.js +++ b/src/wappalyzer.js @@ -322,7 +322,7 @@ class Wappalyzer { * */ ping() { - if (Object.keys(this.hostnameCache).length > 100) { + if (Object.keys(this.hostnameCache).length > 25) { this.driver.ping(this.hostnameCache); this.hostnameCache = {};