MDN self-hosted library · e01.org

EventSource: error event

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
const evtSource = new EventSource("sse.php");

// addEventListener version
evtSource.addEventListener("error", (e) => {
  console.log("An error occurred while attempting to connect.");
});

// onerror version (but note that this replaces other event listeners
// added using onerror, if any)
evtSource.onerror = (e) => {
  console.log("An error occurred while attempting to connect.");
};