Skip to content

Commit

Permalink
Avoid injecting all scripts into non-(X)HTML docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostwords committed Apr 9, 2018
1 parent 90c8de4 commit f6db2db
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/js/contentscripts/clobbercookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* Communicates to webrequest.js to get orders if to delete cookies.
*/


function insertCcScript(text) {
var parent = document.documentElement,
script = document.createElement('script');
Expand All @@ -32,6 +31,19 @@ function insertCcScript(text) {
parent.removeChild(script);
}

// END FUNCTION DEFINITIONS ///////////////////////////////////////////////////

(function () {

// don't inject into non-HTML documents (such as XML documents)
// but do inject into XHTML documents
if (document instanceof HTMLDocument === false && (
document instanceof XMLDocument === false ||
document.createElement('div') instanceof HTMLDivElement === false
)) {
return;
}

// TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({checkLocation:document.location.href}, function(blocked) {
if (blocked) {
Expand All @@ -44,3 +56,5 @@ chrome.runtime.sendMessage({checkLocation:document.location.href}, function(bloc
}
return true;
});

}());
15 changes: 15 additions & 0 deletions src/js/contentscripts/clobberlocalstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ function insertClsScript(text) {
parent.removeChild(script);
}

// END FUNCTION DEFINITIONS ///////////////////////////////////////////////////

(function () {

// don't inject into non-HTML documents (such as XML documents)
// but do inject into XHTML documents
if (document instanceof HTMLDocument === false && (
document instanceof XMLDocument === false ||
document.createElement('div') instanceof HTMLDivElement === false
)) {
return;
}

// TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({checkLocation:document.location.href}, function(blocked) {
if (blocked) {
Expand All @@ -58,3 +71,5 @@ chrome.runtime.sendMessage({checkLocation:document.location.href}, function(bloc
}
return true;
});

}());
16 changes: 16 additions & 0 deletions src/js/contentscripts/fingerprinting.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,20 @@ function insertFpScript(text, data) {
parent.removeChild(script);
}


// END FUNCTION DEFINITIONS ///////////////////////////////////////////////////

(function () {

// don't inject into non-HTML documents (such as XML documents)
// but do inject into XHTML documents
if (document instanceof HTMLDocument === false && (
document instanceof XMLDocument === false ||
document.createElement('div') instanceof HTMLDivElement === false
)) {
return;
}

// TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({checkEnabled: true},
function (enabled) {
Expand All @@ -344,3 +358,5 @@ chrome.runtime.sendMessage({checkEnabled: true},
});
}
);

}());
15 changes: 15 additions & 0 deletions src/js/contentscripts/socialwidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,19 @@ function unblockTracker(buttonUrls, callback) {
chrome.runtime.sendMessage(request, callback);
}

// END FUNCTION DEFINITIONS ///////////////////////////////////////////////////

(function () {

// don't inject into non-HTML documents (such as XML documents)
// but do inject into XHTML documents
if (document instanceof HTMLDocument === false && (
document instanceof XMLDocument === false ||
document.createElement('div') instanceof HTMLDivElement === false
)) {
return;
}

chrome.runtime.sendMessage({
checkSocialWidgetReplacementEnabled: true
}, function (checkSocialWidgetReplacementEnabled) {
Expand All @@ -335,3 +348,5 @@ chrome.runtime.sendMessage({
}
initialize();
});

}());
15 changes: 15 additions & 0 deletions src/js/contentscripts/supercookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ function getScPageScript() {

}

// END FUNCTION DEFINITIONS ///////////////////////////////////////////////////

(function () {

// don't inject into non-HTML documents (such as XML documents)
// but do inject into XHTML documents
if (document instanceof HTMLDocument === false && (
document instanceof XMLDocument === false ||
document.createElement('div') instanceof HTMLDivElement === false
)) {
return;
}

// TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({
checkEnabledAndThirdParty: true
Expand All @@ -134,3 +147,5 @@ chrome.runtime.sendMessage({
});

});

}());

0 comments on commit f6db2db

Please sign in to comment.