Avoid use of prototype functions in inject.js

main
Elbert Alias 8 years ago
parent be78de5aca
commit 4bbda8916b

@ -129,7 +129,7 @@ class Driver {
const scripts = this.getScripts(browser); const scripts = this.getScripts(browser);
const js = this.getJs(browser); const js = this.getJs(browser);
this.wappalyzer.analyze(pageUrl.hostname, pageUrl.href, { this.wappalyzer.analyze(pageUrl, {
headers, headers,
html, html,
js, js,

@ -160,7 +160,7 @@ browser.webRequest.onCompleted.addListener(request => {
( chrome || browser ).runtime.onMessage.addListener((message, sender, sendResponse) => { ( chrome || browser ).runtime.onMessage.addListener((message, sender, sendResponse) => {
if ( typeof message.id != 'undefined' ) { if ( typeof message.id != 'undefined' ) {
if ( message.id !== 'log' ) { if ( message.id !== 'log' ) {
wappalyzer.log('Message received from ' + message.source + ': ' + message.id, 'driver'); wappalyzer.log('Message received' + ( message.source ? ' from ' + message.source : '' ) + ': ' + message.id, 'driver');
} }
var response; var response;

@ -9,35 +9,53 @@
const js = {}; const js = {};
Object.keys(patterns).forEach(appName => { for ( let appName in patterns ) {
js[appName] = {}; if ( patterns.hasOwnProperty(appName) ) {
js[appName] = {};
Object.keys(patterns[appName]).forEach(chain => { for ( let chain in patterns[appName] ) {
js[appName][chain] = {}; if ( patterns[appName].hasOwnProperty(chain) ) {
js[appName][chain] = {};
patterns[appName][chain].forEach((pattern, index) => { for ( let index in patterns[appName][chain] ) {
const value = detectJs(chain); const value = detectJs(chain);
if ( value ) { if ( value ) {
js[appName][chain][index] = value; js[appName][chain][index] = value;
}
}
} }
}); }
}); }
}); }
postMessage({ id: 'js', js }, '*'); postMessage({ id: 'js', js }, '*');
}), false); }), false);
} catch(e) { } catch(e) {
// Fail quietly // Fail quietly
} }
}());
function detectJs(chain) { function detectJs(chain) {
const properties = chain.split('.'); try {
const properties = chain.split('.');
var value = properties.length ? window : null;
for ( let i = 0; i < properties.length; i ++ ) {
var property = properties[i];
const value = properties.reduce((parent, property) => { if ( value.hasOwnProperty(property) ) {
return parent && parent.hasOwnProperty(property) ? parent[property] : null; value = value[property];
}, window); } else {
value = null;
return typeof value === 'string' ? value : !!value; break;
} }
}
return typeof value === 'string' ? value : !!value;
} catch(e) {
// Fail quietly
}
}
}());