Search code examples
javascriptfirefoxprivacynavigatordo-not-track

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


Firefox has launched a feature called Tracking protection in v42.0. It blocks several tracking scripts such as Google Analytics, Marketo, LinkedIn, etc.

Console output of the "Tracking protection" warnings

I was trying to detect it through navigator.DoNotTrack, but it returns unspecified in both cases – browsing in regular mode, and browsing in private mode – using Firefox 42.0 on Mac.

How can I detect in JavaScript whether a user is viewing the website with the Tracking protection on, since navigator.DoNotTrack fails?


Solution

  • navigator.donottrack only shows the setting of the "Do not track" preference. It does not tell if tracking protection, which is a different feature, is enabled. Tracking protection is enabled automatically when in private browsing mode, but users can change a setting in about:config to have it enabled full time.

    While you can't tell directly if the feature is enabled, you can check for its effects with something 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 for its tracking protection; just use a domain that you know is on that list, and an image that you know will exist.

    Of course, this could flag any number of causes for the image not to load, including network connectivity problems, ad blocking software, filtering proxies, etc.