jpillora / xdomain

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

XDomain v0.6 does not work on on IOS 5.1 and IOS 6 (verified on IPAD 1 and other devices) #42

Closed mathieucarbou closed 10 years ago

mathieucarbou commented 10 years ago

v0.6 works on IOS 7 as verified,

v0.5 works on IOS 5.1, 6 and 7 but there is the file upload issue...

Error can be displayed on safari using the console.

----
Javascript: Error
undefined
SYNTAX_ERR: DOM Exception 12: An Invalid or illegal string was specified.
----

This is quite a blocking / urgent bug as it prevent xdomin to be used on these IOS versions.

Found this if it can help:

SYNTAX_ERR code 12
In invalid or illegal string has been specified; for example setting the selectorText property of a CSSStyleRule with an invalid CSS value.

Let us know if we can help / test: the fix is quite urgent for us ;-)

mathieucarbou commented 10 years ago

I am wondering if it is related to line 570: if I change to

xhr.responseType = req.type || '';

the error disappear, the ajax calls are made but it is like the application code does not receive the ajax body response in json.

jpillora commented 10 years ago

Hi @mathieucarbou if that fixes it, I should be able to drop it in. I've only been able to test on safari/chrome/firefox and ie8. I've been meaning to setup automated cross-browser testing though the free services BrowserSwarm and TestlingCI were giving me grief as I needed to setup a static file server and reference it as a different host to simulate cross-domain AJAX.

Not sure what you mean by

application code does not receive the ajax body response in json

So your app is receiving a text response, though its just not an object? or no response at all? does it appear on the network debugger?

mathieucarbou commented 10 years ago

Hi,

It does no fix it at alll: it just prevents the error message from displaying, since, according to the spec, is linked to the fact that responseType is not set to a valid value.

So with this fix, we see no error, we also see the ajax request sent and received correctly. But we do not see any callback triggered. I will check again.

I made a test case here to test easily.

https://gist.github.com/mathieucarbou/fcfd8f4fe2d052be16bb

mathieucarbou commented 10 years ago

Ok i found something.

The fix I made makes things work when issuing ajax requests on the other domain, bridged by xdomain.

But our app also does ajax requests to get a json i18n bundle file from the same domain. This is a simple call like this:

$.getJSON('/locales/' + Locale + '.json', function(i18n){...})

This call is not working with version 0.6 and even with the patched version. With 0.5 it works well.

So it seems to be in the code which detects if it is a normal ajax call or a bridged ajax call I think.

If we set

xdomain.debug = true

we see in the console:

xdomain (http://dashboard-dev.guestful.com): failed to parse url: /locales/en.json 

So i patched parseurl function line 785 to replace the null return by:

  return {
    origin: xdomain.origin,
    path: url
  };

These 2 fixes make it works on Google Chrome, FF, on desktop. On IOS, the first fix prevents the error message, but the second fix does nothing. The requests does not seem to be sent.

So... it remains IOS now...

I cannot tell if those 2 patches have impatcs elsewhere but they seem to work.

jpillora commented 10 years ago

Hi @mathieucarbou sorry for the late reply. @aseemk found the bug: https://github.com/jpillora/xhook/issues/11 In the process of merging into XDomain now...