The onmessage property of the EventSource interface is an EventHandler called when a message event is received, that is when a message is coming from the source.

Event objects of onmessage event handers are of type MessageEvent.


eventSource.onmessage = function


evtSource.onmessage = function(e) {
  var newElement = document.createElement("li");

  newElement.textContent = "message: " +;

Note: You can find a full example on GitHub — see Simple SSE demo using PHP.


Specification Status Comment
HTML Living Standard
The definition of 'onmessage' in that specification.
Living Standard Initial definition

Browser compatibility

ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
onmessageChrome Full support 6Edge Full support 79Firefox Full support 6IE No support NoOpera Full support YesSafari Full support 5WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 45Opera Android Full support 12Safari iOS Full support 5Samsung Internet Android Full support 1.0


Full support
Full support
No support
No support

See also