diff --git a/src/drivers/webextension/js/content.js b/src/drivers/webextension/js/content.js index ac21ee724..f7bab8ecd 100644 --- a/src/drivers/webextension/js/content.js +++ b/src/drivers/webextension/js/content.js @@ -5,25 +5,25 @@ init: function() { var html = document.documentElement.outerHTML; - c.log('init'); + c.log('Function call: init()'); if ( html.length > 50000 ) { html = html.substring(0, 25000) + html.substring(html.length - 25000, html.length); } - browser.runtime.sendMessage({ id: 'analyze', subject: { html: html } }); + browser.runtime.sendMessage({ id: 'analyze', subject: { html: html }, source: 'content.js' }); c.getEnvironmentVars(); }, log: function(message) { - browser.runtime.sendMessage({ id: 'log', message: '[ content.js ] ' + message }); + browser.runtime.sendMessage({ id: 'log', message: message, source: 'content.js' }); }, getEnvironmentVars: function() { var container, script; - c.log('getEnvironmentVars'); + c.log('Function call: getEnvironmentVars()'); if ( typeof document.documentElement.innerHTML === 'undefined' ) { return; @@ -48,7 +48,7 @@ environmentVars = environmentVars.split(' ').slice(0, 500); - browser.runtime.sendMessage({ id: 'analyze', subject: { env: environmentVars } }); + browser.runtime.sendMessage({ id: 'analyze', subject: { env: environmentVars }, source: 'content.js' }); }), true); document.documentElement.appendChild(container); diff --git a/src/drivers/webextension/js/driver.js b/src/drivers/webextension/js/driver.js index 4dee2dd54..b6b1e1d2e 100644 --- a/src/drivers/webextension/js/driver.js +++ b/src/drivers/webextension/js/driver.js @@ -26,7 +26,7 @@ * Log messages to console */ log: function(args) { - console.log('[wappalyzer ' + args.type + '] ' + args.message); + console.log('[wappalyzer ' + args.type + ']', '[' + args.source + ']', JSON.parse(args.message)); }, /** @@ -53,7 +53,7 @@ * Initialize */ init: function() { - w.log('init'); + w.log('Function call: w.driver.init()', 'driver'); // Load apps.json var xhr = new XMLHttpRequest(); @@ -122,8 +122,6 @@ } browser.tabs.onRemoved.addListener(function(tabId) { - w.log('remove tab'); - tabCache[tabId] = null; }); @@ -153,8 +151,6 @@ } } } - - w.log(JSON.stringify({ uri: uri, headers: responseHeaders })); } }, { urls: [ 'http://*/*', 'https://*/*' ], types: [ 'main_frame' ] }, [ 'responseHeaders' ]); @@ -178,11 +174,13 @@ a = document.createElement('a'); if ( typeof message.id != 'undefined' ) { - w.log('message: ' + message.id); + if ( message.id !== 'log' ) { + w.log('Message received from ' + message.source + ': ' + message.id, 'driver'); + } switch ( message.id ) { case 'log': - w.log(message.message); + w.log(message.message, message.source); break; case 'analyze': @@ -295,8 +293,6 @@ if ( Object.keys(w.ping.hostnames).length && tracking ) { w.driver.post('http://ping.wappalyzer.com/v2/', w.ping); - w.log('w.driver.ping: ' + JSON.stringify(w.ping)); - w.ping = { hostnames: {} }; w.driver.post('https://ad.wappalyzer.com/log/wp/', w.adCache); @@ -318,7 +314,7 @@ xhr.onreadystatechange = function() { if ( xhr.readyState == 4 ) { - w.log('w.driver.post: status ' + xhr.status + ' (' + url + ')'); + w.log({ 'POST request': { url: url, status: xhr.status, data: data } }, 'driver'); } }; diff --git a/src/drivers/webextension/js/popup.js b/src/drivers/webextension/js/popup.js index 70808bb53..eb760d34c 100644 --- a/src/drivers/webextension/js/popup.js +++ b/src/drivers/webextension/js/popup.js @@ -1,24 +1,17 @@ /** global: chrome */ /** global: browser */ -document.addEventListener('DOMContentLoaded', function() { - var - slugify, popup, - d = document, - detectedApps = d.getElementById('detected-apps'); - - slugify = function(string) { - return string.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/--+/g, '-').replace(/(?:^-|-$)/, ''); - }; - - popup = { +(function() { + var popup = { init: function() { var callback = function(tabs) { - if ( tabs[0].url.match(/https?:\/\//) ) { - detectedApps.innerHTML = '
' + browser.i18n.getMessage('noAppsDetected') + '
'; - } else { - detectedApps.innerHTML = '
' + browser.i18n.getMessage('nothingToDo') + '
'; - } + ( chrome || browser ).runtime.sendMessage({ id: 'get_apps', tab: tabs[0], source: 'popup.js' }, function(response) { + if ( /complete|interacrive|loaded/.test(document.readyState) ) { + popup.displayApps(response) + } else { + document.addEventListener('DOMContentLoaded', function() { popup.displayApps(response) }); + } + }); }; try { @@ -28,62 +21,56 @@ document.addEventListener('DOMContentLoaded', function() { // Edge browser.tabs.query({ active: true, currentWindow: true }, callback); } - - popup.displayApps(); }, - displayApps: function() { - var appName, confidence, version; + displayApps: function(response) { + var + appName, confidence, version, + detectedApps = document.querySelector('#detected-apps'); + html = ''; - var callback = function(tabs) { - function sendGetApps(response) { - var html; - - if ( response.tabCache && response.tabCache.count > 0 ) { - detectedApps.innerHTML = ''; + if ( response.tabCache && response.tabCache.count > 0 ) { + for ( appName in response.tabCache.appsDetected ) { + confidence = response.tabCache.appsDetected[appName].confidenceTotal; + version = response.tabCache.appsDetected[appName].version; - for ( appName in response.tabCache.appsDetected ) { - confidence = response.tabCache.appsDetected[appName].confidenceTotal; - version = response.tabCache.appsDetected[appName].version; + html += + '
' + + '' + + '' + + '' + + '' + appName + '' + + ( version ? ' ' + version : '' ) + ( confidence < 100 ? ' (' + confidence + '% sure)' : '' ) + + '' + + ''; - html = - '
' + - '' + - '' + - '' + appName + '' + ( version ? ' ' + version : '' ) + ( confidence < 100 ? ' (' + confidence + '% sure)' : '' ) + '' + - ''; + response.apps[appName].cats.forEach(function(cat) { + html += + '' + + '' + browser.i18n.getMessage('categoryName' + cat) + '' + + ''; + }); - response.apps[appName].cats.forEach(function(cat) { - html += - '' + - '' + browser.i18n.getMessage('categoryName' + cat) + '' + - ''; - }); + html += + '' + + '
'; + } + } else { + html = '
' + browser.i18n.getMessage('noAppsDetected') + '
'; + } - html += - '' + - '
'; + detectedApps.innerHTML = html; - detectedApps.innerHTML = detectedApps.innerHTML + html; - } - } - } - if (typeof chrome === "undefined") { - browser.runtime.sendMessage({ id: 'get_apps', tab: tabs[0] }, sendGetApps); - } else { - chrome.runtime.sendMessage({ id: 'get_apps', tab: tabs[0] }, sendGetApps); - } - }; + // Force redraw after popup animation on Mac OS + setTimeout(function() { + document.body.innerHTML += ' '; + }, 600); + }, - try { - // Chrome, Firefox - browser.tabs.query({ active: true, currentWindow: true }).then(callback); - } catch ( e ) { - // Edge - browser.tabs.query({ active: true, currentWindow: true }, callback); - } + slugify: function(string) { + return string.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/--+/g, '-').replace(/(?:^-|-$)/, ''); } }; popup.init(); -}); +}()); diff --git a/src/drivers/webextension/popup.html b/src/drivers/webextension/popup.html index 1548d426e..afa6e0976 100644 --- a/src/drivers/webextension/popup.html +++ b/src/drivers/webextension/popup.html @@ -4,7 +4,6 @@ - diff --git a/src/wappalyzer.js b/src/wappalyzer.js index 4169dc428..aa7b2f03e 100644 --- a/src/wappalyzer.js +++ b/src/wappalyzer.js @@ -109,7 +109,7 @@ var wappalyzer = (function() { */ var driver = function(func, args) { if ( typeof w.driver[func] !== 'function' ) { - w.log('not implemented: w.driver.' + func, 'warn'); + w.log('not implemented: w.driver.' + func, 'core', 'warn'); return; } @@ -154,7 +154,7 @@ var wappalyzer = (function() { } catch (e) { attrs.regex = new RegExp(); - w.log(e + ': ' + attr, 'error'); + w.log(e + ': ' + attr, 'error', 'core'); } } }); @@ -197,8 +197,9 @@ var wappalyzer = (function() { /** * Log messages to console */ - log: function(message, type) { + log: function(message, source, type) { driver('log', { + source: source || '', message: JSON.stringify(message), type: type || 'debug' }); @@ -208,13 +209,13 @@ var wappalyzer = (function() { * Initialize */ init: function() { - w.log('w.init'); + w.log('Function call: w.init()', 'core'); // Initialize driver if ( w.driver !== undefined ) { driver('init'); } else { - w.log('No driver, exiting'); + w.log('No driver, exiting', 'core'); } }, @@ -226,10 +227,10 @@ var wappalyzer = (function() { app, apps = {}; - w.log('w.analyze'); + w.log('Function call: w.analyze()', 'core'); if ( w.apps === undefined || w.categories === undefined ) { - w.log('apps.json not loaded, check for syntax errors'); + w.log('apps.json not loaded, check for syntax errors', 'core'); return; } @@ -279,7 +280,9 @@ var wappalyzer = (function() { w.cacheDetectedApps(apps, url); w.trackDetectedApps(apps, url, hostname, data.html); - w.log(Object.keys(apps).length + ' apps detected: ' + Object.keys(apps).join(', ') + ' on ' + url); + if ( Object.keys(apps).length ) { + w.log(Object.keys(apps).length + ' apps detected: ' + Object.keys(apps).join(', ') + ' on ' + url, 'core'); + } driver('displayApps'); }, @@ -292,7 +295,7 @@ var wappalyzer = (function() { // Exclude app in detected apps only for ( app in apps ) { if ( w.apps[app].excludes ) { - asArray(w.apps[app]).excludes.forEach(function(excluded) { + asArray(w.apps[app].excludes).forEach(function(excluded) { excludes.push(excluded); }); } @@ -325,7 +328,7 @@ var wappalyzer = (function() { implied = parsePatterns(implied)[0]; if ( !w.apps[implied.string] ) { - w.log('Implied application ' + implied.string + ' does not exist', 'warn'); + w.log('Implied application ' + implied.string + ' does not exist', 'core', 'warn'); return; }