According to WHATWG - Server-Sent Events below is the API for using EventSource interface:
[Constructor(DOMString url, optional EventSourceInit eventSourceInitDict)]
interface EventSource : EventTarget {
readonly attribute DOMString url;
readonly attribute boolean withCredentials;
//....
};
The withCredentials attribute must return the value to which it was last initialized. When the object is created, it must be initialized to false.
Simple example:
var stocks = new EventSource("events.php");
stocks.onmessage = function (event) {
//alert(event.data);
};