to stop Google from hijacking Search results URLs for tracking purposes when you click them
Wrong, there's a lot of ways websites profile you. One other method is your device fingerprint, the combination of hardware, software and network information that normally gets sent to the server. A server can then compute a hash and link it to you.
No matter how you block the click-jacked search results, if you end up on a page that happens to have some widget that reports back to their server (with the same hardware, software and network info), consider yourself tracked. These "widgets" come in a variety of forms, like ads, like buttons, tweet buttons, follow buttons etc.
As for your code...
node.onmousedown = null
You are only removing the inline/property handler. You're not preventing handlers that are assigned via addEventListener
and delegated (handlers assigned to ancestors to listen to a descendant).
function foo(message){
alert('No stopping ' + message);
}
var link = document.querySelector('a');
// Assigned as a property
link.onmousedown = function(){
foo('property');
};
// Assigned as listener
link.addEventListener('mousedown', function(){
foo('handler');
});
// Body property
document.body.onmousedown = function(){
foo('delegated property');
};
// Delegated handler
document.body.addEventListener('mousedown', function(){
foo('delegated handler');
});
// Your script only does this:
link.onmousedown = null;
<a href="#foo" onmousedown="foo('inline')">Test</a>
Now there's several steps needed to prevent it.
First, we cannot prevent addEventListener
handles since removeEventListener
requires the reference of the handle function which we normally don't have access to. The best we could do is to clone the node, which doesn't copy over handlers assigned via addEventListener
.
Then we override the inline onmousedown
by defining your own function. Then we prevent delegated handlers by calling stopPropagation
.
Lastly, we replace the original element with the clone.
function foo(message){
alert('No stopping ' + message);
}
var link = document.querySelector('a');
// Assigned as a property
link.onmousedown = function(){
foo('property');
};
// Assigned as listener
link.addEventListener('mousedown', function(){
foo('handler');
});
// Body property
document.body.onmousedown = function(){
foo('delegated property');
};
// Delegated handler
document.body.addEventListener('mousedown', function(){
foo('delegated handler');
});
var clone = link.cloneNode(true);
clone.onmousedown = function(event){
event.stopPropagation();
}
link.parentNode.replaceChild(clone, link);
<a href="#foo" onmousedown="foo('inline')">Test</a>
onmousedown
? I'm pretty sure the majority of their tracking is in their outbound links viahref
, which you cannot circumvent, even if you were to removeonmousedown
(you can verify this by looking at theira
tags in search results). \$\endgroup\$href
part: when I execute a search the results'<a />
have the correcthref
s, they get modified through JavaScript'sonmousedown
event handler set on the<a />
; so if you remove theonmousedown
event no URL hijack takes place (and then you can copy the result URL by right clicking it too!). See [i.sstatic.net/biEQd.png] \$\endgroup\$