jpillora / xdomain

A pure JavaScript CORS alternative
https://jpillora.com/xdomain/
3.12k stars 269 forks source link

xdomain (): Timeout waiting on iframe socket #126

Closed bradniksa closed 9 years ago

bradniksa commented 9 years ago

I have a simple $.ajax call

getContactList : function (email) {
        var $d = $.Deferred();

        $.ajax({
            type: "POST",
            url: 'http://leapcommunication.com/development/americasmart-com/iconhonors/dev/includes/php/getContactsList.php',
            dataType: "text",
            data: {"data": email},
            success: function (data) {
             $d.resolve(data); 
            },
            error: function (xhr, status, error) {
                // console.log('ajax error!!! ' + status);
            }
        }); 
        return $d.promise();
    },

I am getting this error - xdomain (http://go.americasmart.com): Timeout waiting on iframe socket this is a current version of chrome

Site XHR is on http://go.americasmart.com/iconhonors/entry-list

<script src="//cdn.rawgit.com/jpillora/xdomain/0.6.17/dist/xdomain.min.js" slave="http://leapcommunication.com/proxy.html"></script>

Proxy.html @ http://leapcommunication.com/proxy.html

<script src="//cdn.rawgit.com/jpillora/xdomain/0.6.17/dist/xdomain.min.js" </script>
<script>
xdomain.masters({
        'http://go.americasmart.com': '*' 
    });
</script>

Here is a network error on the proxy file

xdomain

Here is the Debug code xdomain (http://go.americasmart.com): adding slave: http://leapcommunication.com xdomain.min.js:3 xdomain (http://go.americasmart.com): proxying request to slave: 'http://leapcommunication.com' xdomain.min.js:3 xdomain (http://go.americasmart.com): creating iframe xdomain-f7ad0302 xdomain.min.js:3 xdomain (http://go.americasmart.com): new socket: xdomain-c833a639 xdomain.min.js:3 xdomain (http://go.americasmart.com): proxying request to slave: 'http://leapcommunication.com' xdomain.min.js:3 xdomain (http://go.americasmart.com): new socket: xdomain-3c0d3f13 xdomain.min.js:3 xdomain (http://go.americasmart.com): proxying request to slave: 'http://leapcommunication.com' xdomain.min.js:3 xdomain (http://go.americasmart.com): new socket: xdomain-92aaec8f xdomain.min.js:3 xdomain (http://go.americasmart.com): proxying request to slave: 'http://leapcommunication.com' xdomain.min.js:3 xdomain (http://go.americasmart.com): new socket: xdomain-91919a3b xdomain.min.js:3 xdomain (http://leapcommunication.com): adding master: http://go.americasmart.com 4xdomain.min.js:3 xdomain (http://go.americasmart.com): Timeout waiting on iframe socket

Any help would be much appreciated

jpillora commented 9 years ago

So the timeout is definitely being caused by the (cancelled) request to proxy.html, however I'm not sure why it's being cancelled. Maybe the iframe is being removed?

If I create a small page with just:

<script src="//cdn.rawgit.com/jpillora/xdomain/0.6.17/dist/xdomain.min.js" slave="http://leapcommunication.com/proxy.html"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script>
    $.get("http://leapcommunication.com/");
</script>

In the logs, we see:

xdomain.min.js:3 xdomain (http://leapcommunication.com): adding master: http://go.americasmart.com
xdomain.min.js:3 xdomain (http://leapcommunication.com): new socket: xdomain-a3881674
xdomain.min.js:3 xdomain (http://leapcommunication.com): blocked request from: 'http://fiddle.jshell.net'
xdomain.min.js:3 xdomain (http://leapcommunication.com): receive socket: xdomain-a3881674: 'XD_CHECK'
xdomain.min.js:3 xdomain (http://leapcommunication.com): send socket: xdomain-a3881674: ready
xdomain.min.js:3 xdomain (http://leapcommunication.com): ready socket: xdomain-a3881674 (emit #0 pending)
xdomain.min.js:3 xdomain (http://leapcommunication.com): receive socket: xdomain-a3881674: 'ready'
xdomain.min.js:3 xdomain (http://leapcommunication.com): receive socket: xdomain-a3881674: 'request'
xdomain.min.js:3 xdomain (http://leapcommunication.com): receive socket: xdomain-a3881674: 'XD_CHECK'

It would have worked if the domain wasn't blocked (blocked request from: 'http://fiddle.jshell.net')

Please recreate this issue on a simpler page and I'll take another look because at the moment it's hard to figure out what's happening

bradniksa commented 9 years ago

Its weird, because I have another page at http://go.americasmart.com/inspire2015 where xdomain is working fine, only difference is the the ajax call on this page is initiated by a user interaction where the other page with the error, xdomain is called on page load, ill play around a little more and try to narrow down the issue, thanks for your response.

ok, here is a simple page http://go.americasmart.com/xdomain Turns out if set the ajax call to a click event vs on page load it works fine, any ideas why we are error on that file only during page load?

Maybe this http://stackoverflow.com/questions/12009423/what-does-status-canceled-for-a-resource-mean-in-chrome-developer-tools

EvenOng commented 9 years ago

HI,

if hit error, xdomain (): Timeout waiting on iframe socket.

How to do error handling on this? for example: when hit this error, direct user to error page.

EvenOng commented 9 years ago

ping @jpillora

jpillora commented 9 years ago

@bradniksa it wouldn't be about when it's used. The XDomain demo does an Ajax on load and it seems to work. Did you figure it out?

@EvenOng you can handle it with the on("timeout",...) API see docs, It will only happen if your proxy.html doesn't load, so it should never happen once your page is setup correctly

EvenOng commented 9 years ago

Hi @jpillora ,

This correct? Now it always log out me no matter timeout or not.

xdomain.on('timeout', errorHandling());

function errorHandling(){ window.location = "http://a.test.com/logout.php" ; }

jpillora commented 9 years ago

try dropping the (), so just errorHandling, the () makes it call the function, you want to pass the function itself

On Mon, Jan 19, 2015 at 7:43 PM, EvenOng notifications@github.com wrote:

Hi @jpillora https://github.com/jpillora ,

if this correct? Now it always log out me no matter timeout or not.

xdomain.on('timeout', errorHandling());

function errorHandling(){ window.location = "http://a.test.com/logout.php" ; }

— Reply to this email directly or view it on GitHub https://github.com/jpillora/xdomain/issues/126#issuecomment-70460992.

phillip-haydon commented 7 years ago

@jpillora I just hit this.

It will only happen if your proxy.html doesn't load

This isn't true. The html page loads fine, but still throws this error. I can't for the life of me figure out why. Calling everything slave/master has confused me too, as well as naming the domains abc/xyz. :/