Skip to content

Instantly share code, notes, and snippets.

@lukepothier
Last active October 15, 2022 23:38
Show Gist options
  • Save lukepothier/1b18905039b1ed960efebec36dc63168 to your computer and use it in GitHub Desktop.
Save lukepothier/1b18905039b1ed960efebec36dc63168 to your computer and use it in GitHub Desktop.
Tampermonkey script to prevent websites from tracking you using favicon fingerprinting
// ==UserScript==
// @name Defeat supercookie (https://github.com/jonasstrehle/supercookie)
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Prevent websites from tracking you using favicon fingerprinting
// @author Luke Pothier <[email protected]>
// @match https://*/*
// @match http://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
onDocumentReady(function() {
let req = new XMLHttpRequest();
req.open('GET', getFavicon(), true);
req.send(null);
});
})();
function onDocumentReady(func) {
if (document.readyState === 'complete' || document.readyState === 'interactive') {
setTimeout(func, 1);
} else {
document.addEventListener('DOMContentLoaded', func);
}
}
function getFavicon() {
let favicon = window.location.origin + '/favicon.ico';
let nodes = document.getElementsByTagName('link');
for (let i = 0; i < nodes.length; i++)
{
if((nodes[i].getAttribute('rel') === 'icon') ||
(nodes[i].getAttribute('rel') === 'shortcut icon'))
{
favicon = nodes[i].getAttribute('href');
}
}
return favicon;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment