sysend.js icon indicating copy to clipboard operation
sysend.js copied to clipboard

Any codesandbox or code example for implementing cross domain communications

Open chaitanyamean opened this issue 3 years ago • 6 comments

chaitanyamean avatar Feb 09 '22 09:02 chaitanyamean

No, because it's impossible to have Coodesandbox and for example Codepen demo. You would need to add an iframe on those domains that are not possible. To have cross domain communication you need to have your own server that you control, like the one on the two domains I control https://jcubic.pl/sysend.php

jcubic avatar Feb 09 '22 10:02 jcubic

But if you want one end I can create a Codepen demo that will send a message to https://jcubic.pl/sysend.php but I'm not sure if this will help you in any way.

jcubic avatar Feb 09 '22 10:02 jcubic

Thanks, For cross domain, message is broadcasting from one web server to other but not vice versa. Can you please let me know anything i am missing

chaitanyamean avatar Feb 28 '22 09:02 chaitanyamean

It's because you need to have an iframe on both domains, There is open PR #30 but I think it would be a real security issue if the library allows both directions communication when only one page has an iframe. I need to investigate maybe add some API to protect the page that has an iframe on it, so you can specify which domain can receive messages.

If you don't protect the server the attacker can steal potentially sensitive information. Also, the PR breaks old code with two iframes.

jcubic avatar Feb 28 '22 09:02 jcubic

Feature of a single proxy HTML file is tracked in #37. The code was moved to the devel branch because the solution in PR was not usable and I was not able to make it work.

jcubic avatar Mar 25 '22 18:03 jcubic

It seems that the library stopped working on CodeSandbox. Just tried it to use in the ReactJS project. The module is loaded when the page has already been loaded and the load event handler is not triggered. Which makes the whole library broken. I've tried to debug on CodeSandbox but because Overwrite Panel doesn't work with Service Worker, I was not able to quickly test it.

jcubic avatar Jun 28 '22 21:06 jcubic

Sorry for the long delay. It seems that one file for Cross-domain communication is not needed for CodeSandbox since you can create a proxy HTML file on CodeSandbox.

Here is an example of Cross-Domain communication:

https://codesandbox.io/s/proxy-demo-hpfc53?file=/index.html

You need to use demo.html from the repo and run it on port 8000 (I used python3 -m http.server command in sysend repository).

To have two-side communication you need to edit the proxy locally and add domain of the CodeSandbox origin (for me it was "https://hpfc53.csb.app").

jcubic avatar Aug 22 '22 09:08 jcubic