Open Bug 833462 Opened 12 years ago Updated 1 year ago

EventSource (SSE) throws JS error on page reload

Categories

(Core :: DOM: Core & HTML, defect, P5)

18 Branch
x86
macOS
defect

Tracking

()

People

(Reporter: dana, Unassigned)

References

()

Details

Attachments

(3 files)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/536.28.8 (KHTML, like Gecko) Version/6.0.3 Safari/536.28.8

Steps to reproduce:

Created an EventSource, verify it is connected, reload page.


Actual results:

Receive console error "The connection to http://<hostname>/<path>/eventsource.php was interrupted while the page was loading."


Expected results:

The EventSource should have closed silently.
Priority: -- → P3
Please provide a testcase/public URL.
Priority: P3 → --
Flags: needinfo?(dana)
This is a server php script to demonstrate this bug.
Flags: needinfo?(dana)
Attachment #705651 - Attachment mime type: text/plain → text/html
Component: Untriaged → DOM: Events
Product: Firefox → Core
Component: DOM: Events → DOM
Olli or Masatoshi-san, could you have a look at what's happening here?
We just print stuff to console as expected, but I guess we should try to not do that in this case.
Can someone provide a few hints about how to fix this? It's pretty annoying for us, and I might be able to hack on it.
Status: UNCONFIRMED → NEW
Ever confirmed: true
(In reply to Dirkjan Ochtman (:djc) from comment #6)
> Can someone provide a few hints about how to fix this? It's pretty annoying
> for us, and I might be able to hack on it.

You probably want to skip sending a message to the console if the result code EventSource::OnStopRequest gets is NS_BINDING_ABORTED.
In particular, I'd also want to not fire the EventSource error event.
Also, please note that as of (at least) FireFox 22.0, this same error is now showing up for WebSocket. Not sure if it's the same fix, but both EventSource and WebSocket should not throw a console error on page refresh. I think the request to also not fire the "error" event should be fixed as well.
Priority: -- → P5
Component: DOM → DOM: Core & HTML

For those that need it a work around I'm using is to close the eventSource before the page closes.

const eventSource = new EventSource('/api/v1/firehose');
window.addEventListener('beforeunload', () => {
	eventSource.close();
});

Issue is still present in Firefox 95.0.2 (64-bit)

Severity: normal → S3

Without the

window.addEventListener("beforeunload", handleClose);

i get the following error:

Firefox can’t establish a connection to the server at http://localhost:3001/v1/stream/events.

when i add the "beforeunload", i still get an error, but a different one:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3001/v1/stream/events. (Reason: CORS request did not succeed). Status code: (null).

Does anyone else have the same problem?

(This is not a general CORS problem. The connection is established without further problems. It is exclusively about the reload).

(In reply to Fynn from comment #12)

Without the

window.addEventListener("beforeunload", handleClose);

i get the following error:

Firefox can’t establish a connection to the server at http://localhost:3001/v1/stream/events.

when i add the "beforeunload", i still get an error, but a different one:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3001/v1/stream/events. (Reason: CORS request did not succeed). Status code: (null).

Does anyone else have the same problem?

(This is not a general CORS problem. The connection is established without further problems. It is exclusively about the reload).

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: