Refactoring

main
Elbert Alias 7 years ago
parent 8c5aaac4f9
commit ef0d8ad593

@ -279,8 +279,12 @@ wappalyzer.driver.getRobotsTxt = (host, secure = false) => {
fetch('http' + ( secure ? 's' : '' ) + '://' + host + '/robots.txt') fetch('http' + ( secure ? 's' : '' ) + '://' + host + '/robots.txt')
.then(response => { .then(response => {
if ( !response.ok ) { if ( !response.ok ) {
if (response.status === 404) {
return '';
} else {
throw 'GET ' + response.url + ' was not ok'; throw 'GET ' + response.url + ' was not ok';
} }
}
return response.text(); return response.text();
}) })

@ -131,7 +131,7 @@ var exports = {};
} }
}, },
ifTrackingEnabled: function(callback, elseCallback) { askIfTrackingEnabled: function(callback, elseCallback) {
this.sendToBackground( this.sendToBackground(
'is_tracking_enabled', 'is_tracking_enabled',
@ -181,7 +181,7 @@ var exports = {};
video_assets: opt_video_assets, video_assets: opt_video_assets,
assets: opt_assets, assets: opt_assets,
version: '3', version: '3',
mrev: 'a80971b-c', mrev: '082d7cb-d',
msgNum: this.msgNum, msgNum: this.msgNum,
timestamp: new Date().getTime(), timestamp: new Date().getTime(),
pageVis: document.visibilityState, pageVis: document.visibilityState,
@ -890,7 +890,7 @@ var exports = {};
var _pageTags; var _pageTags;
var INIT_MS_BW_SEARCHES = 2000; var INIT_MS_BW_SEARCHES = 2000;
var PAGE_TAG_RE = new RegExp('gpt|oascentral'); var PAGE_TAG_RE = new RegExp('gpt|oascentral');
var POST_MSG_ID = '1498662251-16965-9321-27566-5783'; var POST_MSG_ID = '1501281986-4236-27733-5465-12184';
var AD_SERVER_RE = new RegExp('^(google_ads_iframe|oas_frame|atwAdFrame)'); var AD_SERVER_RE = new RegExp('^(google_ads_iframe|oas_frame|atwAdFrame)');
function getPageTags(doc) { function getPageTags(doc) {
@ -1136,12 +1136,12 @@ if ( exports.utils.SCRIPT_IN_WINDOW_TOP ) {
window.adparser = { window.adparser = {
init: exports.coordinator.init, init: exports.coordinator.init,
addPostMessageListener: exports.coordinator.addPostMessageListener, addPostMessageListener: exports.coordinator.addPostMessageListener,
ifTrackingEnabled: exports.utils.ifTrackingEnabled, askIfTrackingEnabled: exports.utils.askIfTrackingEnabled,
sendToBackground: exports.utils.sendToBackground sendToBackground: exports.utils.sendToBackground
}; };
} else { } else {
exports.coordinator.addPostMessageListener(); exports.coordinator.addPostMessageListener();
exports.utils.ifTrackingEnabled( exports.utils.askIfTrackingEnabled(
function() { function() {
exports.coordinator.init(function() {}); exports.coordinator.init(function() {});
}, },
@ -1156,7 +1156,7 @@ if ( exports.utils.SCRIPT_IN_WINDOW_TOP ) {
if ( window === window.top ) { if ( window === window.top ) {
adparser.addPostMessageListener(); adparser.addPostMessageListener();
adparser.ifTrackingEnabled( adparser.askIfTrackingEnabled(
function() { function() {
adparser.init(onAdFound); adparser.init(onAdFound);
}, },

@ -114,23 +114,35 @@
} }
} }
function ifTrackingEnabled(ifCallback, elseCallback) { function ifTrackingEnabled(url, ifCallback, elseCallback) {
var fullIfCallback = function() {
allowedByRobotsTxt(url, ifCallback, elseCallback);
};
browser.storage.local.get('tracking').then(function(item) { browser.storage.local.get('tracking').then(function(item) {
if ( item.hasOwnProperty('tracking') ) { if ( item.hasOwnProperty('tracking') ) {
if ( item.tracking ) { if ( item.tracking ) {
ifCallback(); fullIfCallback();
} else { } else {
elseCallback(); elseCallback();
} }
} else { } else {
ifCallback(); fullIfCallback();
} }
}); });
} }
function allowedByRobotsTxt(url, ifCallback, elseCallback) {
if ( ! url.startsWith('chrome://') ) {
wappalyzer.robotsTxtAllows(url).then(ifCallback, elseCallback);
} else {
elseCallback();
}
}
function isPixelRequest(request) { function isPixelRequest(request) {
return (request.type === 'image' || request.responseStatus === 204) && return (request.type === 'image' || request.responseStatus === 204) &&
request.size <= 1000; request.size <= 1000;
@ -207,6 +219,7 @@
this.cleanupCollector(tabId); this.cleanupCollector(tabId);
ifTrackingEnabled( ifTrackingEnabled(
details.url,
function() { function() {
if ( !areListenersRegistered ) { if ( !areListenersRegistered ) {
@ -792,12 +805,13 @@
browserProxy.runtime.onMessage.addListener(function(request, sender, sendResponse) { browserProxy.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if ( request === 'is_tracking_enabled' ) { if ( request === 'is_tracking_enabled' ) {
ifTrackingEnabled( ifTrackingEnabled(
sender.tab.url,
function() { function() {
sendResponse({'tracking_enabled': true}); try {sendResponse({'tracking_enabled': true});}
}, catch(err) {} },
function() { function() {
sendResponse({'tracking_enabled': false}); try {sendResponse({'tracking_enabled': false});}
} catch(err) {}}
); );
} }
return true; return true;

@ -116,7 +116,7 @@ wappalyzer.robotsTxtAllows = url => {
wappalyzer.driver.getRobotsTxt(parsed.host, parsed.protocol === 'https:') wappalyzer.driver.getRobotsTxt(parsed.host, parsed.protocol === 'https:')
.then(robotsTxt => { .then(robotsTxt => {
robotsTxt.forEach(disallow => { robotsTxt.forEach(disallow => {
if ( parsed.pathname.search(disallow) === 0 ) { if ( parsed.pathname.indexOf(disallow) === 0 ) {
reject(); reject();
} }
}); });

Loading…
Cancel
Save