最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firefox blocking Facebook Js - Stack Overflow

programmeradmin2浏览0评论

with upgrade of Firefox to 42.0 I got some strange behavior..

I'm calling FB.init method like this:

FB.init({ 
        appId: '{$appid}',
        status: true, 
        cookie: true,
        xfbml: true,
        oauth: true
    });

But in Firefox it gets blocked, I get warning:

The resource at ".js" was blocked because tracking protection is enabled.

This is default behavior, I didn't set up any additional security or whatever..

What to do?

EDIT - after help and googling, this is a little bigger problem:

Turns out Firefox's Do Not Track and tracking protection are two separate things:

Do Not Track is enabled in Preferences/Options > Privacy > "Tell sites that I do not want to be tracked". Enabling sends the DNT header but it does not block any requests.

Tracking Protection is enabled in about:config > privacy.trackingprotection.enabled. Enabling does not send the DNT header, but does block requests based on Disconnect's blocklist. So detecting 2 isn't as easy as checking navigator.doNotTrack, because that property is only set for 1.

Solution (temporarily) - try to do FB.init, if error do some alert..

try {
        FB.init({ 
            appId: '{$appid}',
            status: true, 
            cookie: true,
            xfbml: true,
            oauth: true
        });
    }catch(err) {
        alert('Some info for the user...');
    }

Does anyone have better solution?

with upgrade of Firefox to 42.0 I got some strange behavior..

I'm calling FB.init method like this:

FB.init({ 
        appId: '{$appid}',
        status: true, 
        cookie: true,
        xfbml: true,
        oauth: true
    });

But in Firefox it gets blocked, I get warning:

The resource at "https://connect.facebook.net/en_US/all.js" was blocked because tracking protection is enabled.

This is default behavior, I didn't set up any additional security or whatever..

What to do?

EDIT - after help and googling, this is a little bigger problem:

Turns out Firefox's Do Not Track and tracking protection are two separate things:

Do Not Track is enabled in Preferences/Options > Privacy > "Tell sites that I do not want to be tracked". Enabling sends the DNT header but it does not block any requests.

Tracking Protection is enabled in about:config > privacy.trackingprotection.enabled. Enabling does not send the DNT header, but does block requests based on Disconnect's blocklist. So detecting 2 isn't as easy as checking navigator.doNotTrack, because that property is only set for 1.

Solution (temporarily) - try to do FB.init, if error do some alert..

try {
        FB.init({ 
            appId: '{$appid}',
            status: true, 
            cookie: true,
            xfbml: true,
            oauth: true
        });
    }catch(err) {
        alert('Some info for the user...');
    }

Does anyone have better solution?

Share Improve this question edited Nov 22, 2015 at 19:29 Peter asked Nov 22, 2015 at 14:03 PeterPeter 7283 gold badges17 silver badges34 bronze badges 4
  • 3 Is this occuring in a Private Browsing window? – Jaromanda X Commented Nov 22, 2015 at 14:11
  • On my Firefox 42.0 it works. It might be one of your issues... – vanntile Commented Nov 22, 2015 at 14:13
  • Hi, how have you fixed this issue? I mean, the solution can't be just go in the about:config because the system's user will not do that... – Gabrielle Commented Aug 5, 2016 at 13:39
  • hi, its based on client setup.. – Peter Commented Aug 9, 2016 at 16:41
Add a comment  | 

4 Answers 4

Reset to default 7

A simple google search leads to this page: https://developer.mozilla.org/en-US/Firefox/Privacy/Tracking_Protection

You should be able to deactivate that feature right where the message appears, or via about:config. It should actually be deactivated by default afaik.

From the client side, you can't. This is security policy Firefox. You can read about this issue in thread: https://bugzilla.mozilla.org/show_bug.cgi?id=1226498

If any one is coming to this post to find how to handle this error. I think this answer may help.

            (function (d, s, id) {
                let js,
                    fjs = d.getElementsByTagName(s)[0];
                if (d.getElementById(id)) {
                    return;
                }
                js = d.createElement(s);

//here goes the error handling 
                js.onerror = (e) => {
                    //here we can handle the error
                    //we can show the user why the page isn't loading correctly
                }

                js.id = id;
                js.src = 'https://connect.facebook.net/en_US/sdk.js';
                fjs.parentNode.insertBefore(js, fjs);
            })(document, 'script', 'facebook-jssdk');

A way to go about it is checking whether the FB object exists after all script resources have been loaded. In this way we are covered regardless of what caused the script load failure:

$(window).on("load", function() {

    // If Facebook SDK failed to load ... 
    if (typeof FB === "undefined") {

         // ... then change interface/set global variable to handle missing FB

    }

});
发布评论

评论列表(0)

  1. 暂无评论