jpillora / xdomain

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

xdomain breaking prototype chain of XMLHttpRequest #207

Open instantaphex opened 6 years ago

instantaphex commented 6 years ago

I'm not sure if this project is still alive but, it seems to be breaking the latest zone.js which is a dependency of Angular. Zone.js has a few checks that happen when patching XMLHttpRequest that check for property descriptors on XMLHttpRequest.prototype. These are failing. Zone.js patches most of the async host api's which include XMLHttpRequestEventTarget. The problem is that xdomain creates a prototype chain that looks like this:

XMLHttpRequest -> f() -> Function

When not using xdomain the prototype chain looks like this

XMLHttpRequest -> XMLHttpRequestEventTarget -> EventTarget -> Function -> Object

Zone.js is checking the XMLHttpRequestObject like this

Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, 'onreadystatechange');

and that returns some anonymous function (probably xdomains monkey patched function which delegates to some xdomain code first). The end result is that zone.js doesn't patch what it needs to patch and my app breaks.

Now I know that this library isn't responsible for the way in which zone.js decides to hack up browser apis, but if xdomain isn't compatible with Angular, that is a pretty big issue.

It looks like it might be the way you are attaching properties that normally belong to XMLHttpRequestEventTarget directly onto the patched xhr object. Any thoughts?

zzJinux commented 6 years ago

It's been 7 months, still in no response...
I'm trying to test the Angular frontend on local machine, with the backend on remote. I really need the compatibility with zone.js, since the test must be run on IE9, which is CORS-unfriendly (unlike iE10+).
Without the support of xdomain, the only way is to deploy a duplicate backend on local, and it's not desirable...

mkontula commented 5 years ago

Also seeing this issue with Angular 7. Should we consider xdomain a dead project? @jpillora?