Add requestTimeout option, timer for debugging

main
Elbert Alias 7 years ago
parent 727215463c
commit aebf15b841

@ -33,6 +33,7 @@ node index.js [url] [options]
--max-urls=num Exit when num URLs have been analyzed. --max-urls=num Exit when num URLs have been analyzed.
--max-wait=ms Wait no more than ms milliseconds for page resources to load. --max-wait=ms Wait no more than ms milliseconds for page resources to load.
--recursive=0|1 Follow links on pages (crawler). --recursive=0|1 Follow links on pages (crawler).
--request-timeout=ms Wait no more than ms millisecond for the page to load.
--user-agent=str Set the user agent string. --user-agent=str Set the user agent string.
``` ```
@ -45,8 +46,9 @@ const options = {
delay: 500, delay: 500,
maxDepth: 3, maxDepth: 3,
maxUrls: 10, maxUrls: 10,
maxWait: 3000, maxWait: 1000,
recursive: true, recursive: true,
requestTimeout: 3000,
userAgent: 'Wappalyzer', userAgent: 'Wappalyzer',
}; };

@ -15,8 +15,9 @@ class Driver {
delay: 500, delay: 500,
maxDepth: 3, maxDepth: 3,
maxUrls: 10, maxUrls: 10,
maxWait: 3000, maxWait: 1000,
recursive: false, recursive: false,
requestTimeout: 3000,
userAgent: 'Mozilla/5.0 (compatible; Wappalyzer)', userAgent: 'Mozilla/5.0 (compatible; Wappalyzer)',
}, options || {}); }, options || {});
@ -41,6 +42,11 @@ class Driver {
} }
analyze() { analyze() {
this.time = {
start: new Date().getTime(),
last: new Date().getTime(),
}
return this.crawl(this.origPageUrl); return this.crawl(this.origPageUrl);
} }
@ -49,6 +55,8 @@ class Driver {
} }
displayApps(detected) { displayApps(detected) {
this.timer('displayApps');
Object.keys(detected).forEach(appName => { Object.keys(detected).forEach(appName => {
const app = detected[appName]; const app = detected[appName];
@ -76,6 +84,8 @@ class Driver {
} }
fetch(pageUrl, index, depth) { fetch(pageUrl, index, depth) {
this.timer('fetch');
return new Promise(resolve => { return new Promise(resolve => {
// Return when the URL is a duplicate or maxUrls has been reached // Return when the URL is a duplicate or maxUrls has been reached
if ( this.analyzedPageUrls.indexOf(pageUrl.href) !== -1 || this.analyzedPageUrls.length >= this.options.maxUrls ) { if ( this.analyzedPageUrls.indexOf(pageUrl.href) !== -1 || this.analyzedPageUrls.length >= this.options.maxUrls ) {
@ -94,16 +104,22 @@ class Driver {
this.sleep(this.options.delay * index) this.sleep(this.options.delay * index)
.then(() => { .then(() => {
browser.visit(pageUrl.href, error => { this.timer('browser.visit start');
browser.visit(pageUrl.href, this.options.requestTimeout, error => {
this.timer('browser.visit end');
if ( !browser.resources['0'] || !browser.resources['0'].response ) { if ( !browser.resources['0'] || !browser.resources['0'].response ) {
this.wappalyzer.log('No response from server', 'browser', 'error'); this.wappalyzer.log('No response from server', 'browser', 'error');
return resolve(); return resolve();
} }
browser.wait() browser.wait(this.options.maxWait)
.catch(error => this.wappalyzer.log(error.message, 'browser', 'error')) .catch(error => this.wappalyzer.log(error.message, 'browser', 'error'))
.finally(() => { .finally(() => {
this.timer('browser.wait end');
const headers = {}; const headers = {};
browser.resources['0'].response.headers._headers.forEach(header => { browser.resources['0'].response.headers._headers.forEach(header => {
@ -145,6 +161,8 @@ class Driver {
} }
crawl(pageUrl, index = 1, depth = 1) { crawl(pageUrl, index = 1, depth = 1) {
this.timer('crawl');
return new Promise(resolve => { return new Promise(resolve => {
this.fetch(pageUrl, index, depth) this.fetch(pageUrl, index, depth)
.then(links => { .then(links => {
@ -158,13 +176,27 @@ class Driver {
return Promise.resolve(); return Promise.resolve();
} }
}) })
.then(() => resolve(this.apps)); .then(() => {
this.timer('done');
resolve(this.apps)
});
}); });
} }
sleep(ms) { sleep(ms) {
return ms ? new Promise(resolve => setTimeout(resolve, ms)) : Promise.resolve(); return ms ? new Promise(resolve => setTimeout(resolve, ms)) : Promise.resolve();
} }
timer(step) {
const time = new Date().getTime();
const sinceStart = ( Math.round(( time - this.time.start ) / 10) / 100) + 's';
const sinceLast = ( Math.round(( time - this.time.last ) / 10) / 100) + 's';
this.wappalyzer.log('[' + step + '] Time lapsed: ' + sinceLast + ' / ' + sinceStart, 'driver');
this.time.last = time;
}
}; };
module.exports = Driver; module.exports = Driver;

@ -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.1.6", "version": "5.2.0",
"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.1.6", "version": "5.2.0",
"default_locale": "en", "default_locale": "en",
"manifest_version": 2, "manifest_version": 2,
"icons": { "icons": {

Loading…
Cancel
Save