How to determine if a user is using tracking protection in Firefox 42+

Firefox launched the Tracking Protection feature in version 42.0. It blocks several tracking scripts like Google Analytics, Marketo, LinkedIn, etc.

Console exit

I tried to detect it through navigator.DoNotTrack , but it returns unspecified in both cases - browsing in normal mode and browsing in private mode - using Firefox 42.0 on Mac.

How can I determine in JavaScript if a user is browsing on a website with tracking protection since navigator.DoNotTrack fails?

+11
javascript firefox privacy navigator do-not-track
source share
2 answers

navigator.donottrack only shows the Do Not Track setting. It does not report if tracking protection is enabled, which is another feature. Tracking protection is automatically enabled in private browsing mode, but users can change the setting approximately: config to enable full-time.

While you cannot directly indicate whether this function is enabled, you can check its effects like this:

 var canreach = false; $(function() { $('<img/>') .attr("src", "//apps.facebook.com/favicon.ico") .load(function(){canreach = true;}) .css("display", "none") .appendTo(document.body); }); 

Firefox uses a list obtained from Disconnect to protect it from tracking; just use the domain that you know is on this list and the image that you know will exist.

Of course, this can mean any number of reasons why the image does not load, including problems with the network connection, ad blocking software, proxy filtering, etc.

+11
source share

Here is a slightly improved version of miken32's answer using Deferred:

 function whenNoTrackingProtection() { if (!whenNoTrackingProtection.promise) { var dfd = new $.Deferred(); whenNoTrackingProtection.promise = dfd.promise(); var time = Date.now(); $('<img/>') .attr('src', '//apps.facebook.com/favicon.ico') .on('load', dfd.resolve) .on('error', function() { if ((Date.now() - time) < 50) { dfd.reject(); } else { // The request took to long, it seems this is a network error. dfd.resolve(); } }); } return whenNoTrackingProtection.promise; } 

or without jQuery using Promise:

 function whenNoTrackingProtection() { if (!whenNoTrackingProtection.promise) { whenNoTrackingProtection.promise = new Promise(function(resolve, reject) { var time = Date.now(); var img = new Image(); img.onload = resolve; img.onerror = function() { if ((Date.now() - time) < 50) { reject(); } else { // The request took to long, it seems this is a network error. resolve(); } }; img.src = '//apps.facebook.com/favicon.ico'; }); } return whenNoTrackingProtection.promise; } 
+5
source share

All Articles