SSE collection error: SECURITY_ERR: DOM 18 exception with server that provides events sent by server (SSE)

I am trying to connect browsers with a server that provides server events (SSE). This server has a different domain than the original. For example, if you call http://d1.example.com/page , this page will try to connect to the SSE channel at http://d2.example.com/subscribe . Attempting to do this will cause the following error:

Uncaught Error: SECURITY_ERR: DOM Exception 18

in line:

var source = new EventSource("http://d2.example.com/subscribe")

How can i fix this?

Update (the solutions I tried):

1- CORS

I tried CORS by adding Access-Control-Allow-Origin:* to the headers of my d2.example.com web service. This did not solve the EventSource problem, although $.get("http://d2.example.com") calls from d1.example.com now work fine! I thought SSE works with regular HTTP requests, so why doesn't it work in Chrome?

2- Redirection

I use an httpd server, so I created a forwarding rule in the d1.example.com virtual host that sends SSE requests to d2.example.com . It worked great with Firefox. Chrome, on the other hand, did not cause any errors and did not connect to the SSE server. It looks like he dropped the entire EventSource command. It seems like this solution will never work, so let's move on ...

3- Reverse proxy

Both browsers are connected to d1.example.com/subscribe , which basically connects to d2.example.com through a reverse proxy. But the on_close event never catches, even if the browser is closed. This makes sense, since the d2 server now creates a channel with a proxy server. How can I redirect the on_close event from the proxy to d2?

Are there any other ways that could make this work?

+6
source share
1 answer

This is most likely a resource sharing problem between resources, which you should include in the respective domains.

http://enable-cors.org/

Because MDN says:

Note. Although not yet part of the standard, EventSource supports CORS in Firefox 11 and later. This is expected to become standard soon.

+4
source

All Articles