From 4089cd1dcd7c303e709331c299521266a0b2bdd7 Mon Sep 17 00:00:00 2001 From: NateN1222 Date: Sat, 27 Jan 2018 10:54:08 -0600 Subject: Added pre-request blocking for Google Analytics so that Google cannot register that the script was even requested. --- main_background.js | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'main_background.js') diff --git a/main_background.js b/main_background.js index 4d60869..bf7feff 100644 --- a/main_background.js +++ b/main_background.js @@ -32,9 +32,10 @@ console.log("main_background.js"); * */ var DEBUG = false; +var PRINT_DEBUG = true function dbg_print(a,b){ - if(DEBUG == true){ + if(PRINT_DEBUG == true){ if(b === undefined){ console.log(a); } else{ @@ -1652,10 +1653,12 @@ function full_evaluate(script){ } } var error_count = 0; - while(toke.type != acorn_base.tokTypes.eof){ + while(toke !== undefined && toke.type != acorn_base.tokTypes.eof){ if(toke.type.keyword !== undefined){ + //dbg_print("Keyword:"); + //dbg_print(toke); + // This type of loop detection ignores functional loop alternatives and ternary operators - //dbg_print("Keyword:"+toke.type.keyword); if(toke.type.keyword == "function"){ dbg_print("%c NONTRIVIAL: Function declaration.","color:red"); @@ -1963,7 +1966,25 @@ function get_script(response,url,tabid,wl,index=-1){ }); }); } - +function block_ga(a){ + console.log(a.url); + // This is actually just an HTML page + if(a.url == 'https://www.google.com/analytics/#?modal_active=none'){ + return; + } + if(a.url.match(/https:\/\/www\.google\.com\/analytics\//g)){ + dbg_print("%c Google analytics (1)","color:red"); + return {cancel: true}; + } + if(a.url == 'https://www.google-analytics.com/analytics.js'){ + dbg_print("%c Google analytics (2)","color:red"); + return {cancel: true}; + } + if(a.url == 'https://www.google.com/analytics/js/analytics.min.js'){ + dbg_print("%c Google analytics (3)","color:red"); + return {cancel: true}; + } +} function read_script(a){ var filter = webex.webRequest.filterResponseData(a.requestId); @@ -2141,6 +2162,20 @@ function init_addon(){ webex.storage.onChanged.addListener(options_listener); webex.tabs.onRemoved.addListener(delete_removed_tab_info); + // Prevents Google Analytics from being loaded from Google servers + var all_types = [ + "beacon", "csp_report", "font", "image", "imageset", "main_frame", "media", + "object", "object_subrequest", "ping", "script", "stylesheet", "sub_frame", + "web_manifest", "websocket", "xbl", "xml_dtd", "xmlhttprequest", "xslt", + "other" + ] + // Analyzes remote scripts + webex.webRequest.onBeforeRequest.addListener( + block_ga, + {urls:[""], types:all_types}, + ["blocking"] + ); + // Analyzes remote scripts webex.webRequest.onBeforeRequest.addListener( read_script, -- cgit v1.2.3