开发者

FB.login dialog does not close on Google Chrome

I'm calling FB.login() on a click event in my application. The dialog pops up as expected, but when the user is done logging into Facebook (and/or authorizing the app), the dialog does not close. Instead it loads a white page (inside the dialog) and the title changes to XD Proxy.

This only happens on Google Chrome (I'm using the latest version available right now for Windows 7).

This doesn't happen if Chrome is in Incognito mode.

The fb-login 'social plugin' works fine on Chrome.

To test/debug this further, I created a new Facebook App with vanilla settings. The only change I made was set the Site URL in the app settings. Here's HTML code that you can use to recreate this bug.

Sample Code for recreating issue

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Chrome Bug Test</title>
    </head>
    <body>
        <button onclick="dologin()">Login using Facebook</button>

        <div id="fb-root"></div>
        <script src="http://connect.facebook.net/en_US/all.js"></script>
        <script>
          FB.init({
            appId  : '[YOUR APP ID HERE]',
            status : true, // check login status
            cookie : true, // enable cookies to allow the server to access the session
            xfbml  : true  // parse XFBML
          });
        </script>

        <script type="text/javascript开发者_如何转开发">
            function dologin(){
                FB.login(function(r){
                    if(console && console.log) {
                        console.log(r);
                    }
                });
            }
        </script>

    </body>
</html>

Facebook Settings that I've tried changing

  1. Setting a site domain, didn't change anything.
  2. Using a custom channelUrl and channel file, didn't help either.

Related bugs tracked at Facebook

  • http://bugs.developers.facebook.net/show_bug.cgi?id=14789
  • https://github.com/facebook/connect-js/issues/269
  • http://bugs.developers.facebook.net/show_bug.cgi?id=12112
  • http://developers.facebook.com/bugs/278247488872084

Related issues here on Stack Overflow

  • Blank popup with FB connect
  • facebook connect blank pop up on chrome
  • Facebook Connect Login redirecting in Chrome and Safari
  • https://stackoverflow.com/questions/4423718/blank-page-with-fb-connect-js-sdk-on-after-permission-request
  • Facebook connect showing blank popup on login in Internet explorer 8
  • Facebook login popup window stays open when using Fb.login in IE
  • JS SDK FB.login() works but pop-up dialog is staying open after logged in
  • Facebook login hangs at "XD Proxy" when page is installed via Chrome Web Store
  • XD Proxy Facebook
  • XD_Proxy popup won't close

I've seen many people come across this, but what bugs me is that I haven't been able to find a concrete fix for this. Facebook hasn't responded to bug reports yet. One solution would be get rid of Javascript based authentication code and do it solely using serverside mechanism (Facebook PHP SDK). I'd like to avoid that due to time constraints.

Anyone have any ideas how to fix this?


I got a similar call to FB.login() to close the dialog box by changing

onclick="dologin()"

to

onclick="dologin(); return false;"


Given the age of this post, I am guessing that the poster has solved this; however, given that this is also a resource for others searching to resolve similar issues, I thought that I would include my experience just in case.

I found out that what was causing this same issue symptom for me was accidentally forgetting to include event.preventDefault(); in my "click" listener handler in jQuery. The facebook login dialog was popping up and allowing me to log in but not disappearing. The issue was that the website was performing the default form post action, which was interfering with the facebook call-back function.


I had the same exact problem. I did two things, first I added this line right before the FB.init() call:

FB.Flash.hasMinVersion = function () { return false; };

Then I went into the FB app page and added the Site Domain (i.e. test.com).

I think the site domain setting was the key, but I am not 100% positive. All I know is that it seems to always close now in all browsers including Chrome.


Short answer relating to question above:

Load the all.js script over https.

<script src="https://connect.facebook.net/en_US/all.js"></script>

Longer answer if you are troubleshooting a similar issue to the original question:

Use Google Chrome to attempt the login. Once you have logged in and have the blank pop-up window hanging up on the screen, press F12. This brings up the developer tools for Chrome. Click the Console tab, and you will hopefully see the error. What you will likely see is related to XD (cross-domain) issues.

Even if your particular issue is different from the issue I was having, the above should lead you in the right direction.

My issue/solution was specific the Facebook C# SDK v6 documentation - the tutorial code loads the all.js script using a URL that begins with // - which then loads the script from the same scheme as my site (which was http). After I logged in, the pop-up tried to redirect me back from the https Facebook login to my http site and bingo, we have the XD issue. The solution was to specifically load the scripts from https://connect.facebook.net/en_US/all.js as follows:

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "https://connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));

Edit:

After some consideration, this approach of allowing a redirect to http might compromise the security of the system by allowing the data in that request to be read by someone else and then to be re-used. I couldn't find any relevant documentation or examples and so I could not conclude one way or another, YMMV.


Calling this snippet after FB.init fixed the issue for me. But other solutions seem to have worked for different cases.

$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
if ($.browser.chrome || $.browser.msie) {
    FB.XD._origin = window.location.protocol + "//" + document.domain + "/" + FB.guid();
    FB.XD.Flash.init();
    FB.XD._transport = "flash";
  } else if ($.browser.opera) {
    FB.XD._transport = "fragment";
    FB.XD.Fragment._channelUrl = window.location.protocol + "//" + window.location.host + "/";
  }


I've been experiencing the same issue in IE9, and it seemed to stem from upgrading to Flash Player 10. The answers suggested already did not work for me and I'd lost hope in trying to fix it since finding an open bug at Facebook covering it. But Henson has posted an answer on a similar question that fixed it for me. In the JavaScript in my site master I removed these lines

    FB.UIServer.setLoadedNode = function (a, b) {
       //HACK: http://bugs.developers.facebook.net/show_bug.cgi?id=20168
        FB.UIServer._loadedNodes[a.id] = b;
    };

and now it works. (N.B. I have not checked to see if the IE8 issue those lines were intended to overcome returns.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜