Skip to content

Commit

Permalink
Switch to onCommitted for content script injection
Browse files Browse the repository at this point in the history
  • Loading branch information
alexristich committed Apr 14, 2018
1 parent 7053026 commit ddeada1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,9 @@ Badger.prototype = {
return;
}

var executeScriptCallback = function() {
var noop = function() {
if (chrome.runtime.lastError) {
// Do nothing
// // Do nothing
}
};

Expand All @@ -813,29 +813,29 @@ Badger.prototype = {
'file': '/js/contentscripts/fingerprinting.js',
'frameId': frame_id,
'runAt': 'document_start'
}, executeScriptCallback);
}, noop);
chrome.tabs.executeScript(tab_id, {
'file': '/js/contentscripts/clobbercookie.js',
'frameId': frame_id,
'runAt': 'document_start'
}, executeScriptCallback);
}, noop);
chrome.tabs.executeScript(tab_id, {
'file': '/js/contentscripts/clobberlocalstorage.js',
'frameId': frame_id,
'runAt': 'document_start'
}, executeScriptCallback);
}, noop);
chrome.tabs.executeScript(tab_id, {
'file': '/js/contentscripts/supercookie.js',
'frameId': frame_id,
'runAt': 'document_idle'
}, executeScriptCallback);
}, noop);

if (this.isSocialWidgetReplacementEnabled()) {
chrome.tabs.executeScript(tab_id, {
'file': '/js/contentscripts/socialwidgets.js',
'frameId': frame_id,
'runAt': 'document_start'
}, executeScriptCallback);
}, noop);
}
},

Expand Down
2 changes: 0 additions & 2 deletions src/js/contentscripts/fingerprinting.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/

function getFpPageScript() {

console.log('inserting fp script');
// code below is not a content script: no chrome.* APIs /////////////////////

// return a string
Expand Down
1 change: 0 additions & 1 deletion src/js/contentscripts/socialwidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ let i18n = chrome.i18n;
* Initializes the content script.
*/
function initialize() {
console.info('insert social widget script');
// Get tracker info and check for initial blocks (that happened
// before content script was attached)
getTrackerData(function (trackers, trackerButtonsToReplace) {
Expand Down
13 changes: 11 additions & 2 deletions src/js/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ var temporarySocialWidgetUnblock = {};

/***************** Blocking Listener Functions **************/

function injectScripts(details) {
var frame_id = details.frameId,
tab_id = details.tabId,
url = details.url;

if (!_isTabChromeInternal(tab_id)) {
badger.insertContentScripts(tab_id, url, frame_id);
}
}

/**
* Event handling of http requests, main logic to collect data what to block
*
Expand All @@ -63,14 +73,12 @@ function onBeforeRequest(details) {
frame_id = 0;
}

badger.insertContentScripts(tab_id, url, frame_id, is_internal);
badger.recordFrame(tab_id, frame_id, details.parentFrameId, url);

return {};
}

if (type == "sub_frame") {
badger.insertContentScripts(tab_id, url, frame_id, is_internal);
badger.recordFrame(tab_id, frame_id, details.parentFrameId, url);
}

Expand Down Expand Up @@ -708,6 +716,7 @@ function startListeners() {
chrome.webRequest.onBeforeRequest.addListener(onBeforeRequest, {urls: ["http://*/*", "https://*/*"]}, ["blocking"]);
chrome.webRequest.onBeforeSendHeaders.addListener(onBeforeSendHeaders, {urls: ["http://*/*", "https://*/*"]}, ["requestHeaders", "blocking"]);
chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["<all_urls>"]}, ["responseHeaders", "blocking"]);
chrome.webNavigation.onCommitted.addListener(injectScripts);
chrome.tabs.onRemoved.addListener(onTabRemoved);
chrome.tabs.onReplaced.addListener(onTabReplaced);
chrome.runtime.onMessage.addListener(dispatcher);
Expand Down

0 comments on commit ddeada1

Please sign in to comment.