diff --git a/bin/wappalyzer-build b/bin/wappalyzer-build index 9c4989728..b526af24b 100755 --- a/bin/wappalyzer-build +++ b/bin/wappalyzer-build @@ -41,7 +41,7 @@ do rm "$dest" fi - #node $WAPPALYZER_NODE_PATH/node_modules/svg2png/bin/svg2png-cli "$svg" --width=32 --height=32 --output "$dest" || true + node $WAPPALYZER_NODE_PATH/node_modules/svg2png/bin/svg2png-cli "$svg" --width=32 --height=32 --output "$dest" || true done IFS="$OIFS" @@ -52,22 +52,6 @@ node $WAPPALYZER_NODE_PATH/node_modules/imagemin-cli/cli.js $WAPPALYZER_ROOT/src wappalyzer links -# Mozilla Firefox -echo "Building Firefox driver..." - -pushd $WAPPALYZER_ROOT/src/drivers/firefox > /dev/null - -node $WAPPALYZER_NODE_PATH/node_modules/jpm/bin/jpm xpi && mv *.xpi $WAPPALYZER_ROOT/build/wappalyzer_firefox.xpi - -popd > /dev/null - -# Google Chrome -echo "Building Chrome driver..." - -pushd $WAPPALYZER_ROOT/src/drivers/chrome > /dev/null - -zip -qr $WAPPALYZER_ROOT/build/wappalyzer_chrome.zip . - # WebExtension echo "Building WebExtension driver..." diff --git a/bin/wappalyzer-links b/bin/wappalyzer-links index 251cebbf2..ae75f4432 100755 --- a/bin/wappalyzer-links +++ b/bin/wappalyzer-links @@ -30,26 +30,11 @@ echo "Creating hard links..." ln -f $path/wappalyzer.js $path/drivers/phantomjs ln -f $path/apps.json $path/drivers/phantomjs -ln -f $path/wappalyzer.js $path/drivers/firefox -ln -f $path/apps.json $path/drivers/firefox/data -ln -f $path/icons/*.png $path/drivers/firefox/data/images/icons -ln -f $path/icons/*.svg $path/drivers/firefox/data/images/icons -ln -f $path/utils/iframe.js $path/drivers/firefox/data/js - -ln -f $path/wappalyzer.js $path/drivers/chrome/js -ln -f $path/apps.json $path/drivers/chrome -ln -f $path/icons/*.png $path/drivers/chrome/images/icons -ln -f $path/icons/*.svg $path/drivers/chrome/images/icons -ln -f $path/utils/*.js $path/drivers/chrome/js - -if [ "$(compgen -G "$path/icons/converted/*.png" | head -n1)" ]; then - ln -f $path/icons/converted/*.png $path/drivers/chrome/images/icons/converted -fi - ln -f $path/wappalyzer.js $path/drivers/webextension/js ln -f $path/apps.json $path/drivers/webextension ln -f $path/icons/*.png $path/drivers/webextension/images/icons ln -f $path/icons/*.svg $path/drivers/webextension/images/icons +ln -f $path/utils/*.js $path/drivers/webextension/js if [ "$(compgen -G "$path/icons/converted/*.png" | head -n1)" ]; then ln -f $path/icons/converted/*.png $path/drivers/webextension/images/icons/converted diff --git a/docker/Dockerfile b/docker/Dockerfile index ec435c0bd..c4e7806c0 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -8,11 +8,19 @@ ENV WAPPALYZER_ROOT /home/wappalyzer/synced ENV WAPPALYZER_NODE_PATH /home/wappalyzer/node # Install packages +RUN sed -i 's/^deb-src\ /\#deb-src\ /g' /etc/apt/sources.list RUN sed -i 's/archive\.ubuntu\.com/au.archive.ubuntu.com/g' /etc/apt/sources.list -RUN apt-get update && apt-get install -y sudo curl -RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - -RUN apt-get install -y nodejs bzip2 zip libfreetype6 libfontconfig rsync -RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +RUN sed -i 's/security\.ubuntu\.com/au.archive.ubuntu.com/g' /etc/apt/sources.list +RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - && \ + apt-get install -y \ + nodejs \ + bzip2 \ + zip \ + libfreetype6 \ + libfontconfig \ + rsync && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # Add user diff --git a/src/apps.json b/src/apps.json index 04b2f0408..eca8e667e 100755 --- a/src/apps.json +++ b/src/apps.json @@ -9,6 +9,7 @@ "url": "/shop/catalog/browse\\?sessid=", "website": "http://1and1.com" }, + "1C-Bitrix": { "cats": [ "1" @@ -587,6 +588,26 @@ "implies": "Java", "website": "http://wicket.apache.org" }, + "ApexPages": { + "cats": [ + "51" + ], + "headers": { + "X-Powered-By": "Salesforce.com ApexPages" + }, + "icon": "ApexPages.png", + "implies": "Salesforce", + "website": "https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_intro.htm" + }, + "Apostrophe CMS": { + "cats": [ + "1" + ], + "html": "<[^>]+data-apos-refreshable[^>]", + "icon": "apostrophecms.svg", + "implies": "Node.js", + "website": "http://apostrophecms.org" + }, "AppNexus": { "cats": [ "36" @@ -942,6 +963,14 @@ "script": "boba(?:\\.min)?\\.js", "website": "http://boba.space150.com" }, + "Bold Chat": { + "cats": [ + "52" + ], + "icon": "BoldChat.png", + "script": "^https?://vmss\\.boldchat\\.com/aid/\\d{18}/bc\\.vms4/vms\\.js", + "website": "https://www.boldchat.com/" + }, "Bolt": { "cats": [ "1" @@ -1696,7 +1725,7 @@ ], "env": "^d3$", "icon": "D3.png", - "script": "d3(?:\\. v\\d+)?(?:\\.min)?\\.js", + "script": "/d3(?:\\. v\\d+)?(?:\\.min)?\\.js", "website": "http://d3js.org" }, "DHTMLX": { @@ -2003,6 +2032,9 @@ "cats": [ "1" ], + "headers": { + "X-Dotclear-Static-Cache": "" + }, "icon": "Dotclear.png", "implies": "PHP", "website": "http://dotclear.org" @@ -2466,7 +2498,7 @@ ], "icon": "FancyBox.png", "implies": "jQuery", - "script": "jquery\\.fancybox\\.pack\\.js$", + "script": "jquery\\.fancybox\\.pack\\.js(?:\\?v=([\\d.]+))?$\\;version:\\1", "website": "http://fancyapps.com/fancybox" }, "Fat-Free Framework": { @@ -2545,6 +2577,18 @@ }, "website": "http://www.flexcmp.com/cms/home" }, + "FlexSlider": { + "cats": [ + "5", + "7" + ], + "icon": "FlexSlider.png", + "implies": "jQuery", + "script": [ + "jquery\\.flexslider(?:\\.min)?\\.js$" + ], + "website": "https://woocommerce.com/flexslider/" + }, "FluxBB": { "cats": [ "2" @@ -2577,6 +2621,17 @@ "icon": "Font Awesome.png", "website": "http://fontawesome.io" }, + "Fork CMS": { + "cats": [ + "1" + ], + "icon": "ForkCMS.png", + "implies": "Symfony", + "meta": { + "generator": "^Fork CMS$" + }, + "website": "http://www.fork-cms.com/" + }, "Fortune3": { "cats": [ "6" @@ -2724,7 +2779,10 @@ "47" ], "env": "^gerrit_", - "html": "<(?:div|style) id=\"gerrit_", + "html": [ + ">Gerrit Code Review\\s*\"\\s*\\(([0-9.]+)\\)\\;version:\\1", + "<(?:div|style) id=\"gerrit_" + ], "icon": "gerrit.svg", "implies": [ "Java", @@ -2790,7 +2848,6 @@ }, "html": [ "", "
" ], "icon": "GitLab.svg", @@ -3131,6 +3188,18 @@ }, "website": "http://www.greenvalley.nl/Public/Producten/Content_Management/CMS" }, + "Homeland": { + "cats": [ + "1", + "2" + ], + "headers": { + "Set-Cookie:": "_homeland_" + }, + "icon": "Homeland.png", + "implies": "Ruby on Rails", + "website": "https://gethomeland.com" + }, "HERE": { "cats": [ "35" @@ -3375,6 +3444,18 @@ }, "website": "http://hotarucms.org" }, + "Hotjar": { + "cats": [ + "10" + ], + "env": [ + "^HotLeadfactory$", + "^HotleadController$" + ], + "icon": "Hotjar.png", + "script": "^//static\\.hotjar\\.com/c/hotjar-", + "website": "https://www.hotjar.com" + }, "HubSpot": { "cats": [ "32" @@ -4130,6 +4211,14 @@ }, "website": "http://www.komodocms.com" }, + "Kontaktify": { + "cats": [ + "5" + ], + "icon": "Kontaktify.png", + "script": "//(?:www\\.)?kontaktify\\.com/embed.js", + "website": "https://www.kontaktify.com" + }, "Koobi": { "cats": [ "1" @@ -4373,6 +4462,14 @@ "url": "\\.livejournal\\.com", "website": "http://www.livejournal.com" }, + "LivePerson": { + "cats": [ + "52" + ], + "icon": "LivePerson.png", + "script": "^https?://lptag\\.liveperson\\.net/tag/tag\\.js", + "website": "https://www.liveperson.com/" + }, "LiveStreet CMS": { "cats": [ "1" @@ -4747,6 +4844,18 @@ }, "website": "http://www.mediawiki.org" }, + "Medium": { + "cats": [ + "1" + ], + "headers": { + "X-Powered-By": "Medium" + }, + "icon": "Medium.svg", + "script": "medium\\.com", + "url": "^(?:www\\.)?medium\\.com", + "website": "https://medium.com" + }, "Meebo": { "cats": [ "5" @@ -4771,9 +4880,17 @@ "cats": [ "12" ], - "env": "^Meteor$", + "env": [ + "^Meteor$", + "^METEOR_VERSION$" + ], "html": "]+__meteor-css__", "icon": "Meteor.png", + "implies": [ + "MongoDB", + "Node.js", + "jQuery" + ], "website": "http://meteor.com" }, "Methode": { @@ -5256,6 +5373,17 @@ "icon": "Nepso.png", "website": "http://nepso.com" }, + "Netlify": { + "cats": [ + "22", + "31" + ], + "headers": { + "Server": "Netlify" + }, + "icon": "Netlify.svg", + "website": "https://www.netlify.com/" + }, "Netmonitor": { "cats": [ "10" @@ -5327,6 +5455,19 @@ "icon": "node.js.png", "website": "http://nodejs.org" }, + "NodeBB": { + "cats": [ + "2" + ], + "headers": { + "X-Powered-By": "^NodeBB$" + }, + "icon": "NodeBB.png", + "implies": "Node.js", + "script": "^/nodebb\\.min\\.js\\?", + "website": "https://nodebb.org" + }, + "OWL Carousel": { "cats": [ "5", @@ -5390,6 +5531,14 @@ "script": "/web/js/(?:web\\.assets_common/|website\\.assets_frontend/)\\;confidence:25", "website": "http://odoo.com" }, + "Olark": { + "cats": [ + "52" + ], + "icon": "Olark.png", + "script": "^https?:\\/\\/static\\.olark\\.com\\/jsclient\\/loader1\\.js", + "website": "https://www.olark.com/" + }, "OmniTouch 8660 My Teamwork": { "cats": [ "19" @@ -6110,6 +6259,10 @@ "meta": { "generator": "PrestaShop" }, + "headers": { + "Set-Cookie": "^PrestaShop", + "Powered-By": "^Prestashop$" + }, "website": "http://www.prestashop.com" }, "Project Wonderful": { @@ -6475,7 +6628,7 @@ ], "env": "^Reveal$", "icon": "Reveal.js.png", - "script": "reveal(?:\\.min)?\\.js", + "script": "(?:^|/)reveal(?:\\.min)?\\.js", "website": "http://lab.hakim.se/reveal-js" }, "Revel": { @@ -6779,6 +6932,18 @@ "implies": "Express", "website": "http://sailsjs.org" }, + "Salesforce": { + "cats": [ + "53" + ], + "env": "^SFDC(?:App|Cmp|Page|SessionVars)$", + "headers": { + "Set-Cookie": "com\\.salesforce\\." + }, + "html": "<[^>]+=\"brandQuaternaryFgrs\"", + "icon": "Salesforce.svg", + "website": "https://www.salesforce.com" + }, "Sarka-SPIP": { "cats": [ "1" @@ -6817,6 +6982,16 @@ ], "website": "http://schneider-electric.com" }, + "Scholica": { + "cats": [ + "21" + ], + "headers": { + "X-Scholica-Version": "" + }, + "icon": "Scholica.svg", + "website": "http://scholica.com" + }, "Scientific Linux": { "cats": [ "28" @@ -7288,6 +7463,17 @@ }, "website": "http://spidercontrol.net/ininet" }, + "SpinCMS": { + "cats": [ + "1" + ], + "headers": { + "Set-Cookie": "spincms_session" + }, + "icon": "SpinCMS.png", + "implies": "PHP", + "website": "http://www.spin.cw" + }, "Splunk": { "cats": [ "19" @@ -7596,6 +7782,15 @@ "url": "/typo3/", "website": "http://www.typo3.org" }, + "Typecho": { + "cats": [ + "11" + ], + "icon": "typecho.svg", + "implies": "PHP", + "url": "/admin/login\\.php?referer=http%3A%2F%2F", + "website": "http://typecho.org/" + }, "Taiga": { "cats": [ "13" @@ -7630,7 +7825,10 @@ ], "env": "^TEALIUMENABLED$", "icon": "Tealium.png", - "script": "//tags\\.tiqcdn\\.com/", + "script": [ + "^//tags\\.tiqcdn\\.com/", + "/tealium/utag\\.js$" + ], "website": "http://tealium.com" }, "TeamCity": { @@ -7652,9 +7850,12 @@ "cats": [ "1" ], - "env": "Telescope", + "env": "^Telescope$", "icon": "Telescope.png", - "implies": "Meteor", + "implies": [ + "Meteor", + "React" + ], "website": "http://telescopeapp.org" }, "Tengine": { @@ -9786,16 +9987,6 @@ "script": "shine(?:\\.min)?\\.js", "website": "http://bigspaceship.github.io/shine.js/" }, - "spin.js": { - "cats": [ - "12", - "25" - ], - "env": "^Spinner$", - "icon": "spin.js.png", - "script": "spin(?:\\.min)?\\.js", - "website": "http://fgnass.github.io/spin.js/" - }, "swift.engine": { "cats": [ "1" @@ -9882,6 +10073,19 @@ }, "website": "http://www.vbulletin.com" }, + "vibecommerce": { + "cats": [ + "6" + ], + "excludes": "PrestaShop", + "icon": "vibecommerce.png", + "implies": "PHP", + "meta": { + "designer": "vibecommerce", + "generator": "vibecommerce" + }, + "website": "http://vibecommerce.com.br" + }, "viennaCMS": { "cats": [ "1" @@ -9890,16 +10094,6 @@ "icon": "default.svg", "website": "http://www.viennacms.nl" }, - "vis.js": { - "cats": [ - "25" - ], - "env": "^vis$", - "html": "]+?href=\"[^\"]+vis(?:\\.min)?\\.css", - "icon": "vis.js.png", - "script": "vis(?:\\.min)?\\.js", - "website": "http://visjs.org" - }, "webEdition": { "cats": [ "1" @@ -9919,6 +10113,22 @@ "icon": "webpack.svg", "website": "http://webpack.github.io" }, + "wpCache": { + "cats": [ + "23" + ], + "headers": { + "X-Powered-By": "wpCache(?:/([\\d.]+))?\\;version:\\1" + }, + "html": " + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/icons/Scholica.svg b/src/icons/Scholica.svg new file mode 100644 index 000000000..b35216915 --- /dev/null +++ b/src/icons/Scholica.svg @@ -0,0 +1,24 @@ + + + + logo-green-icon + Created with Sketch. + + + + + + + + + \ No newline at end of file diff --git a/src/icons/SpinCMS.png b/src/icons/SpinCMS.png new file mode 100644 index 000000000..f6e947831 Binary files /dev/null and b/src/icons/SpinCMS.png differ diff --git a/src/icons/Telescope.png b/src/icons/Telescope.png old mode 100644 new mode 100755 index 65f03875a..59672bace Binary files a/src/icons/Telescope.png and b/src/icons/Telescope.png differ diff --git a/src/icons/apostrophecms.svg b/src/icons/apostrophecms.svg new file mode 100644 index 000000000..d71a5b5db --- /dev/null +++ b/src/icons/apostrophecms.svg @@ -0,0 +1,12 @@ + + + + 256 + Created with Sketch. + + + + + + + \ No newline at end of file diff --git a/src/icons/cloudcart.svg b/src/icons/cloudcart.svg index 9d608655b..5d5c41cf9 100644 --- a/src/icons/cloudcart.svg +++ b/src/icons/cloudcart.svg @@ -2,7 +2,7 @@ + width="32px" height="32px" viewBox="0 0 500 500"> + + typecho-logo + Created with Sketch (http://www.bohemiancoding.com/sketch) + + + + + + \ No newline at end of file diff --git a/src/icons/vibecommerce.png b/src/icons/vibecommerce.png new file mode 100644 index 000000000..9f8c6a50d Binary files /dev/null and b/src/icons/vibecommerce.png differ diff --git a/src/icons/vis.js.png b/src/icons/vis.js.png deleted file mode 100644 index f40c5df55..000000000 Binary files a/src/icons/vis.js.png and /dev/null differ diff --git a/src/icons/wpCache.png b/src/icons/wpCache.png new file mode 100644 index 000000000..12470ff47 Binary files /dev/null and b/src/icons/wpCache.png differ diff --git a/src/utils/iframe.js b/src/utils/iframe.js index 64e2c20e4..d37f91ef1 100644 --- a/src/utils/iframe.js +++ b/src/utils/iframe.js @@ -69,6 +69,7 @@ var exports = {}; realArray: function(a) { return Array.prototype.slice.apply(a); }, + onDocLoaded: function(doc, callback) { if ( doc.readyState === 'loading' ) { doc.addEventListener('DOMContentLoaded', callback); @@ -118,6 +119,36 @@ var exports = {}; } return dict; }, + sendToBackground: function(message, event, responseMessage, onResponse) { + if ( typeof browser !== 'undefined' ) { + var response = browser.runtime.sendMessage(message); + response.then(onResponse); + } else if ( typeof chrome !== 'undefined' ) { + chrome.runtime.sendMessage(message, onResponse); + } else if ( window.self.port ) { + window.self.port.on(responseMessage, onResponse); + window.self.port.emit(event, message); + } + }, + + ifTrackingEnabled: function(callback, elseCallback) { + + this.sendToBackground( + 'is_tracking_enabled', + '', + 'tracking_enabled_response', + function(message) { + if ( message.tracking_enabled ) { + + callback(); + } else { + + elseCallback(); + } + } + ); + + } }; utils.SCRIPT_IN_FRIENDLY_IFRAME = !utils.SCRIPT_IN_WINDOW_TOP && utils.isFriendlyWindow(window.parent); @@ -137,7 +168,7 @@ var exports = {}; LogGenerator.prototype = { log: function(event, opt_assets, opt_pageTags) { var opt_video_assets; - if ( event === 'video' ) { + if ( event === 'video' || event === 'invalid-video' ) { opt_video_assets = opt_assets || []; opt_assets = []; } else { @@ -150,7 +181,7 @@ var exports = {}; video_assets: opt_video_assets, assets: opt_assets, version: '3', - mrev: '9efbfba-c', + mrev: '9c4d5b3-c', msgNum: this.msgNum, timestamp: new Date().getTime(), pageVis: document.visibilityState, @@ -859,7 +890,7 @@ var exports = {}; var _pageTags; var INIT_MS_BW_SEARCHES = 2000; var PAGE_TAG_RE = new RegExp('gpt|oascentral'); - var POST_MSG_ID = '1488911709-15415-26289-19282-15751'; + var POST_MSG_ID = '1490888598-28717-31700-14775-21098'; var AD_SERVER_RE = new RegExp('^(google_ads_iframe|oas_frame|atwAdFrame)'); function getPageTags(doc) { @@ -925,9 +956,9 @@ var exports = {}; if ( exports.utils.SCRIPT_IN_WINDOW_TOP || document.readyState === 'complete' ) { extractAds(); } - setTimeout(function() { - extractAdsWrapper(); - }, INIT_MS_BW_SEARCHES); + setTimeout( + function() { extractAdsWrapper(); }, INIT_MS_BW_SEARCHES + ); } function extractAds() { @@ -1049,7 +1080,13 @@ var exports = {}; } function addBackgroundListener(event, callback) { - if ( typeof chrome !== 'undefined' ) { + if ( typeof browser !== 'undefined' ) { + browser.runtime.onMessage.addListener(function(msg) { + if ( msg.event === event ) { + callback(msg); + } + }); + } else if ( typeof chrome !== 'undefined' ) { chrome.runtime.onMessage.addListener(function(msg) { if ( msg.event === event ) { callback(msg); @@ -1061,6 +1098,12 @@ var exports = {}; } exports.coordinator = { + addPostMessageListener: function() { + if ( !exports.utils.SCRIPT_IN_FRIENDLY_IFRAME ) { + window.addEventListener('message', onPostMessage, false); + } + }, + init: function(onAdFound) { if ( exports.utils.SCRIPT_IN_FRIENDLY_IFRAME ) { @@ -1068,8 +1111,6 @@ var exports = {}; } _onAdFound = onAdFound; - window.addEventListener('message', onPostMessage, false); - if ( exports.utils.SCRIPT_IN_WINDOW_TOP ) { var log = _logGen.log('page'); onAdFound(log); @@ -1094,26 +1135,32 @@ var exports = {}; if ( exports.utils.SCRIPT_IN_WINDOW_TOP ) { window.adparser = { init: exports.coordinator.init, + addPostMessageListener: exports.coordinator.addPostMessageListener, + ifTrackingEnabled: exports.utils.ifTrackingEnabled, + sendToBackground: exports.utils.sendToBackground }; } else { - exports.coordinator.init(function() {}); + exports.coordinator.addPostMessageListener(); + exports.utils.ifTrackingEnabled( + function() { + exports.coordinator.init(function() {}); + }, + function() {} + ); } - })(window); (function(adparser) { - function sendToBackground(event, message) { - if ( window.self.port ) { - window.self.port.emit(event, message); - } else if ( typeof chrome !== 'undefined' ) { - chrome.extension.sendRequest(message); - } - } - function onAdFound(log) { - sendToBackground('ad_log', { id: 'ad_log', subject: log }); + adparser.sendToBackground({ id: 'ad_log', subject: log }, 'ad_log', '', function(){}); } - if ( window === window.top ) { - adparser.init(onAdFound); + if ( window === window.top ) { + adparser.addPostMessageListener(); + adparser.ifTrackingEnabled( + function() { + adparser.init(onAdFound); + }, + function() {} + ) } })(window.adparser); diff --git a/src/utils/network.js b/src/utils/network.js index 944db09c2..b2f2ea018 100644 --- a/src/utils/network.js +++ b/src/utils/network.js @@ -1,6 +1,27 @@ 'use strict'; (function() { + function isChrome() { + return (typeof chrome !== 'undefined' && + window.navigator.userAgent.match(/Chrom(?:e|ium)\/([0-9\.]+)/)); + } + + var browserProxy; + if ( isChrome() ) { + browserProxy = chrome; + } else { + browserProxy = browser; + } + + var MIN_FF_MAJOR_VERSION = 51; + + var requiredBrowserApis = [ + browserProxy.webNavigation, + browserProxy.tabs, + browserProxy.webRequest, + browserProxy.runtime + ]; + var areListenersRegistered = false; var secBefore = 2000; var secAfter = 5000; var secBetweenDupAssets = 10e3; @@ -58,6 +79,47 @@ }; } + function getFrame(getFrameDetails, callback) { + if ( typeof chrome !== 'undefined' ) { + chrome.webNavigation.getFrame(getFrameDetails, callback); + } else if ( typeof browser !== 'undefined' ) { + var gettingFrame = browser.webNavigation.getFrame(getFrameDetails); + gettingFrame.then(callback); + } + } + + function ifBrowserValid(callback, elseCallback) { + if ( isChrome() ) { + + callback(); + } else if ( typeof browser !== 'undefined' ) { + try { + var gettingInfo = browser.runtime.getBrowserInfo(); + gettingInfo.then(function(browserInfo) { + var browserVersion = parseInt(browserInfo.version.split('.')[0]); + + if ( browserInfo.name === 'Firefox' && + browserVersion >= MIN_FF_MAJOR_VERSION) { + callback(); + } else { + elseCallback(); + } + }); + } catch (err) { + + elseCallback(); + } + } else { + elseCallback(); + } + } + + function isTrackingEnabled() { + + return parseInt(localStorage.tracking, 10); + + } + function isPixelRequest(request) { return (request.type === 'image' || request.responseStatus === 204) && request.size <= 1000; @@ -73,7 +135,7 @@ } function stripQueryParams(url) { - return url.split('?',1)[0]; + return url.split('?', 1)[0]; } function parseHostnameFromUrl(url) { @@ -133,7 +195,18 @@ var tabId = details.tabId; this.cleanupCollector(tabId); - this.collectors[tabId] = new PageNetworkTrafficCollector(tabId); + if ( isTrackingEnabled() ) { + if ( !areListenersRegistered ) { + + registerListeners(); + } + this.collectors[tabId] = new PageNetworkTrafficCollector(tabId); + } else { + if ( areListenersRegistered ) { + + unregisterListeners(); + } + } }, onNavigationCommitted: function(details) { @@ -176,7 +249,7 @@ PageNetworkTrafficCollector.prototype.sendLogMessageToTabConsole = function() { var logMessage = Array.from(arguments).join(' '); var message = {message: logMessage, event: 'console-log-message'}; - chrome.tabs.sendMessage(this.tabId, message); + browserProxy.tabs.sendMessage(this.tabId, message); }; PageNetworkTrafficCollector.prototype.sendToTab = function(assetReq, reqs, curPageUrl, isValidAd) { @@ -195,7 +268,9 @@ return parseHostnameFromUrl(request.url); }); msg.assets = [{ + url: parseHostnameFromUrl(assetReq.url), + contentType: assetReq.contentType, size: assetReq.size }]; @@ -204,7 +279,7 @@ msg.origUrl = curPageUrl; msg.displayAdFound = this.displayAdFound; - chrome.tabs.sendMessage(this.tabId, msg); + browserProxy.tabs.sendMessage(this.tabId, msg); }; PageNetworkTrafficCollector.prototype.getRedirKey = function(url, frameId) { @@ -252,7 +327,7 @@ frameId: details.frameId }; var pageNetworkTrafficController = this; - chrome.webNavigation.getFrame(getFrameDetails, function(frameDetails) { + getFrame(getFrameDetails, function(frameDetails) { if ( frameDetails && frameDetails.url ) { pageNetworkTrafficController._onHeadersReceived(details, frameDetails); } @@ -372,7 +447,7 @@ frameId: responseDetails.frameId }; var pageNetworkTrafficController = this; - chrome.webNavigation.getFrame(getFrameDetails, function(frameDetails) { + getFrame(getFrameDetails, function(frameDetails) { if ( frameDetails && frameDetails.url ) { pageNetworkTrafficController.processResponse(responseDetails, frameDetails); } @@ -518,7 +593,7 @@ var _this = this, origPageUrl, msgAssetReq; msgAssetReq = this.msgsBeingSent[msgKey]; - chrome.tabs.get(this.tabId, function(tab) {origPageUrl = tab.url;}); + browserProxy.tabs.get(this.tabId, function(tab) {origPageUrl = tab.url;}); setTimeout(function() { var rawRequests = []; @@ -551,54 +626,159 @@ } }; - chrome.webRequest.onBeforeRequest.addListener(function(details) { + function onBeforeRequestListener(details) { globalPageContainer.forwardCall(details, PageNetworkTrafficCollector.prototype.onBeforeRequest); - }, {urls: ['http://*/*', 'https://*/*']}, []); + } - chrome.webRequest.onSendHeaders.addListener(function(details) { + function onSendHeadersListener(details) { globalPageContainer.forwardCall(details, PageNetworkTrafficCollector.prototype.onSendHeaders); - }, {urls: ['http://*/*', 'https://*/*']}, ['requestHeaders']); + } - chrome.webRequest.onHeadersReceived.addListener(function(details) { + function onHeadersReceivedListener(details) { globalPageContainer.forwardCall(details, PageNetworkTrafficCollector.prototype.onHeadersReceived); - }, {urls: ['http://*/*', 'https://*/*']}, ['responseHeaders']); + } - chrome.webRequest.onBeforeRedirect.addListener(function(details) { + function onBeforeRedirectListener(details) { globalPageContainer.forwardCall(details, PageNetworkTrafficCollector.prototype.onBeforeRedirect); - }, {urls: ['http://*/*', 'https://*/*']}, []); + } - chrome.webRequest.onResponseStarted.addListener(function(details) { + function onResponseStartedListener(details) { globalPageContainer.forwardCall(details, PageNetworkTrafficCollector.prototype.onResponseStarted); - }, {urls: ['http://*/*', 'https://*/*']}, ['responseHeaders']); - - chrome.webNavigation.onBeforeNavigate.addListener(function(details) { - if ( details.frameId === 0 ) { - globalPageContainer.onNewNavigation(details); - } - }, {}); + } - chrome.webNavigation.onCommitted.addListener(function(details) { + function onCommittedListener(details) { if ( details.frameId === 0 ) { globalPageContainer.onNavigationCommitted(details); } - }); + } - chrome.webNavigation.onCompleted.addListener(function(details) { + function onCompletedListener(details) { if ( details.frameId === 0 ) { globalPageContainer.onNavigationCompleted(details); } - }); + } - chrome.tabs.onRemoved.addListener(function(tabId, closeInfo) { + function onRemovedListener(tabId, closeInfo) { globalPageContainer.onTabClose(tabId, closeInfo); - }); + } - chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { + function onMessageListener(message, sender, sendResponse) { if ( message.event === 'new-ad' && message.data.event === 'ad' ) { var tabId = sender.tab.id; if ( tabId ) { globalPageContainer.onDisplayAdFound(tabId); } } + } + + function registerListeners() { + + browserProxy.webRequest.onBeforeRequest.addListener( + onBeforeRequestListener, + {urls: ['http://*/*', 'https://*/*']}, + [] + ); + + browserProxy.webRequest.onSendHeaders.addListener( + onSendHeadersListener, + {urls: ['http://*/*', 'https://*/*']}, + ['requestHeaders'] + ); + + browserProxy.webRequest.onHeadersReceived.addListener( + onHeadersReceivedListener, + {urls: ['http://*/*', 'https://*/*']}, + ['responseHeaders'] + ); + + browserProxy.webRequest.onBeforeRedirect.addListener( + onBeforeRedirectListener, + {urls: ['http://*/*', 'https://*/*']}, + [] + ); + + browserProxy.webRequest.onResponseStarted.addListener( + onResponseStartedListener, + {urls: ['http://*/*', 'https://*/*']}, + ['responseHeaders'] + ); + + browserProxy.webNavigation.onCommitted.addListener(onCommittedListener); + browserProxy.webNavigation.onCompleted.addListener(onCompletedListener); + browserProxy.tabs.onRemoved.addListener(onRemovedListener); + browserProxy.runtime.onMessage.addListener(onMessageListener); + + areListenersRegistered = true; + } + + function unregisterListeners() { + + browserProxy.webRequest.onBeforeRequest.removeListener( + onBeforeRequestListener + ); + + browserProxy.webRequest.onSendHeaders.removeListener( + onSendHeadersListener + ); + + browserProxy.webRequest.onHeadersReceived.removeListener( + onHeadersReceivedListener + ); + + browserProxy.webRequest.onBeforeRedirect.removeListener( + onBeforeRedirectListener + ); + + browserProxy.webRequest.onResponseStarted.removeListener( + onResponseStartedListener + ); + + browserProxy.webNavigation.onCommitted.removeListener(onCommittedListener); + browserProxy.webNavigation.onCompleted.removeListener(onCompletedListener); + browserProxy.tabs.onRemoved.removeListener(onRemovedListener); + browserProxy.runtime.onMessage.removeListener(onMessageListener); + + areListenersRegistered = false; + } + + function areRequiredBrowserApisAvailable() { + return requiredBrowserApis.every(function(api) { + return typeof api !== 'undefined'; + }); + } + + if ( areRequiredBrowserApisAvailable() ) { + ifBrowserValid( + function() { + browserProxy.webNavigation.onBeforeNavigate.addListener( + function(details) { + if ( details.frameId === 0 ) { + globalPageContainer.onNewNavigation(details); + } + }, + { + url: [{urlMatches: 'http://*/*'}, {urlMatches: 'https://*/*'}] + } + ); + }, function() { + + } + ); + } + + browserProxy.runtime.onMessage.addListener(function(request, sender, sendResponse) { + if ( request === 'is_browser_valid' ) { + ifBrowserValid( + sendResponse({'browser_valid': true}), + sendResponse({'browser_valid': false}) + ); + } }); + + browserProxy.runtime.onMessage.addListener(function(request, sender, sendResponse) { + if ( request === 'is_tracking_enabled' ) { + sendResponse({'tracking_enabled': isTrackingEnabled()}); + } + }); + })();