jpillora / xdomain

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

BUG: Xdomain attempting (and failing) to handle other crossdomain requests on the same page #141

Closed ejbaker closed 9 years ago

ejbaker commented 9 years ago

In production, the page where I'm using xdomain also makes other requests I can't control. (ad units) With debug mode set, I get the following messages:

xdomain (http://stage.www.example.com): adding slave: http://subdomain.example.com:3000 xdomain (http://stage.www.example.com): no slave matching: 'http://diffsubdomain.diffdomain.com'

and at this point, the script shuts down.

Is there any way to constrain xdomain so that it will only attempt to proxy requests directed at its slave?

jpillora commented 9 years ago

When no slave matching appears, it should skip XDomain. In order to hook ajax requests, XHook must replace the entire XMLHttpRequest object. I can't say where things are going wrong based on those logs, can you make a live demo reproducing this? (Please use unminified versions of all included scripts)

As a hacky work around in the meantime, you could initially xhook.disable(), then for every request:

xhook.enable();
$.ajax(...);
xhook.disable();