diff --git a/src/drivers/webextension/js/content.js b/src/drivers/webextension/js/content.js index 7ad284495..df11d725b 100644 --- a/src/drivers/webextension/js/content.js +++ b/src/drivers/webextension/js/content.js @@ -35,7 +35,25 @@ if ( typeof browser !== 'undefined' && typeof document.body !== 'undefined' ) { script.setAttribute('id', 'wappalyzerEnvDetection'); script.setAttribute('src', browser.extension.getURL('js/inject.js')); - container.addEventListener('wappalyzerEvent', (event => { + container.addEventListener('wappalyzerEnvEvent', (event => { + browser.runtime.sendMessage({ + id: 'JS_ready', + subject: { }, + source: 'content.js' + }, response => { + window.postMessage({patterns: response.patterns}, "*"); + }); + window.addEventListener('message', (event => { + if (event.data.js === undefined) + return; + var js = event.data.js ; + browser.runtime.sendMessage({ + id: 'analyze', + subject: { js }, + source: 'content.js' + }); + }), true); + var env = event.target.childNodes[0].nodeValue; document.documentElement.removeChild(container); diff --git a/src/drivers/webextension/js/inject.js b/src/drivers/webextension/js/inject.js index 731db3366..26ac3d6eb 100644 --- a/src/drivers/webextension/js/inject.js +++ b/src/drivers/webextension/js/inject.js @@ -1,42 +1,33 @@ (function() { try { - var i, environmentVars = '', e = document.createEvent('Events'); + var i, environmentVars = '', eEnv = document.createEvent('Events'), container = document.getElementById('wappalyzerData'); - e.initEvent('wappalyzerEvent', true, false); + eEnv.initEvent('wappalyzerEnvEvent', true, false); for ( i in window ) { environmentVars += i + ' '; } + container.appendChild(document.createComment(environmentVars)); + container.dispatchEvent(eEnv); - document.getElementById('wappalyzerData').appendChild(document.createComment(environmentVars)); - document.getElementById('wappalyzerData').dispatchEvent(e); - - // Handle property match - browser.runtime.sendMessage({ - id: 'JS_ready', - subject: { }, - source: 'inject.js' - }, response => { - var properties = response.patterns; + window.addEventListener('message', (event => { + if (event.data.patterns === undefined) + return; + var properties = event.data.patterns; var js = {}; - Object.keys(properties).forEach(app => { - Object.keys(properties[app]).forEach(property => { + Object.keys(properties).forEach(appname => { + Object.keys(properties[appname]).forEach(property => { var content = false; if( content = JSdetection(property) ){ - if ( js[appname] === undefined ) { + if ( js[appname] === undefined ) js[appname] = {}; - } - js[appname][property] = properties[app][property]; + js[appname][property] = properties[appname][property]; js[appname][property]["content"] = content; } }); }); - browser.runtime.sendMessage({ - id: 'analyze', - subject: { js }, - source: 'inject.js' - }); - }); + window.postMessage({js: js}, "*"); + }), false); } catch(e) { // Fail quietly } @@ -49,4 +40,4 @@ function JSdetection(p){ }, window); return typeof value === 'string' ? value : !!value; -} \ No newline at end of file +} diff --git a/src/wappalyzer.js b/src/wappalyzer.js index d76e604f0..74fd66393 100644 --- a/src/wappalyzer.js +++ b/src/wappalyzer.js @@ -18,7 +18,7 @@ class Wappalyzer { this.apps = {}; this.categories = {}; this.driver = {}; - this.parsedJS = {}; + this.parsedJS = undefined; this.detected = {}; this.hostnameCache = {}; @@ -85,7 +85,7 @@ class Wappalyzer { if ( data.js ) { Object.keys(data.js).forEach(appName => { - this.analyzeJS(this.apps[appname], data.js[appname]) + this.analyzeJS(apps[appName], data.js[appName]); }); } @@ -255,14 +255,13 @@ class Wappalyzer { * Parse JS patterns */ parseJS() { - if ( this.parsedJS == {} ){ + if ( this.parsedJS === undefined){ + this.parsedJS = {}; Object.keys(this.apps).forEach(appName => { - if (apps[appName].props.js){ - parsedJS[appName] = this.parsePatterns(apps[appName].props.js); - } + if (this.apps[appName].js) + this.parsedJS[appName] = this.parsePatterns(this.apps[appName].js); }); } - return this.parsedJS } resolveExcludes(apps) {