Emit log and visit events in NPM driver

main
Elbert Alias 6 years ago
parent c728d7f066
commit 87e829ee00

@ -49,6 +49,8 @@ node index.js [url] [options]
const Wappalyzer = require('./driver');
const Browser = require('./browsers/zombie');
const url = 'https://www.wappalyzer.com;
const options = {
debug: false,
delay: 500,
@ -61,10 +63,17 @@ const options = {
htmlMaxRows: 2000,
};
const wappalyzer = new Wappalyzer(Browser, 'https://www.wappalyzer.com', options);
const wappalyzer = new Wappalyzer(Browser, url, options);
// Optional: capture log output
// wappalyzer.on('log', params => {
// const { message, source, type } = params;
// });
// Optionally override the default logger
// wappalyzer.log = (message, source, type) => console.log(message);
// Optional: do something on page visit
// wappalyzer.on('visit', params => {
// const { browser, pageUrl } = params;
// });
wappalyzer.analyze()
.then(json => {

@ -25,6 +25,8 @@ class ZombieBrowser extends Browser {
const resource = this.browser.resources.length
? this.browser.resources.filter(_resource => _resource.response).shift() : null;
this.window = this.browser.window;
this.document = this.browser.document;
this.headers = this.getHeaders();
this.statusCode = resource ? resource.response.status : 0;
this.contentType = this.headers['content-type'] ? this.headers['content-type'].shift() : null;

@ -48,6 +48,7 @@ class Driver {
this.analyzedPageUrls = {};
this.apps = [];
this.meta = {};
this.listeners = {};
this.Browser = Browser;
@ -65,6 +66,20 @@ class Driver {
process.on('uncaughtException', e => this.wappalyzer.log(`Uncaught exception: ${e.message}`, 'driver', 'error'));
}
on(event, callback) {
if (!this.listeners[event]) {
this.listeners[event] = [];
}
this.listeners[event].push(callback);
}
emit(event, params) {
if (this.listeners[event]) {
this.listeners[event].forEach(listener => listener(params));
}
}
analyze() {
this.time = {
start: new Date().getTime(),
@ -78,6 +93,8 @@ class Driver {
if (this.options.debug) {
console.log(`[wappalyzer ${type}]`, `[${source}]`, message);
}
this.emit('log', { message, source, type });
}
displayApps(detected, meta) {
@ -150,11 +167,11 @@ class Driver {
// Validate response
if (!browser.statusCode) {
reject(new Error('NO_RESPONSE'));
return reject(new Error('NO_RESPONSE'));
}
if (browser.statusCode !== 200) {
reject(new Error('RESPONSE_NOT_OK'));
return reject(new Error('RESPONSE_NOT_OK'));
}
if (!browser.contentType || !/\btext\/html\b/.test(browser.contentType)) {
@ -188,6 +205,8 @@ class Driver {
}, [],
);
this.emit('visit', { browser, pageUrl });
return resolve(reducedLinks);
}

@ -1,6 +1,6 @@
{
"name": "wappalyzer",
"version": "5.6.0",
"version": "5.6.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

@ -2,7 +2,7 @@
"name": "wappalyzer",
"description": "Uncovers the technologies used on websites",
"homepage": "https://github.com/AliasIO/Wappalyzer",
"version": "5.6.1",
"version": "5.6.2",
"author": "Elbert Alias",
"license": "GPL-3.0",
"repository": {
@ -12,9 +12,10 @@
"main": "driver.js",
"files": [
"apps.json",
"browser.js",
"browsers/zombie.js",
"index.js",
"driver.js",
"index.js",
"wappalyzer.js"
],
"bin": {

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