jpillora / xdomain

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

Conflicts with existing postMessage logic #82

Closed newtriks closed 10 years ago

newtriks commented 10 years ago

Thanks for the library, seems a solid solution. I was wondering if you envisage conflicts within applications already implementing postMessage? A quick test in an Angular app that calls a rails api seems to create errors in the existing postMessage logic the apps relied on.

jpillora commented 10 years ago

Since post message has a terrible API, this can't be helped - you can create many message listeners, but they will all fire on all messages. XDomain protects itself by only accepting XDomain messages. Basically if you have multiple windows posting you messages, you need to ensure they're discernable. For example in example, I send arrays with something like:

[ "xdomain-ef13ds", { .. actual message }]

So if you can make your code also emit your own wrapper, then you your app can throw away the messages that it doesn't care about

On Friday, May 30, 2014, Simon Bailey notifications@github.com wrote:

Thanks for the library, seems a solid solution. I was wondering if you envisage conflicts within applications already implementing postMessage? A quick test in an Angular app that calls a rails api seems to create errors in the existing postMessage logic the apps relied on.

— Reply to this email directly or view it on GitHub https://github.com/jpillora/xdomain/issues/82.

newtriks commented 10 years ago

@jpillora thanks and I agree about the postMessage API :+1: