Unlike others, for me the EventSource is getting triggered and working fine in both Chrome and Firefox. But in Firefox whenever I receive a message in browser, I receive an error message along with it. Does not happen in Chrome.
Client code:
var source = new EventSource('***');
source.addEventListener('message', function(event) {
...
}, false);
source.addEventListener('ping', function(e) {
...
}, false);
source.addEventListener('error', function(e) {
... // now this part gets executed in firefox, whenever i recieve a msg
}, false);
Server, nodejs code:
***.on('fin',function(message){
delete ***;
res.header('Content-Type', 'text/event-stream');
res.write('data: '+JSON.stringify(message)+'\n\n');
res.end();
});
***.on('busError',function(){
delete ***;
res.send(500);
});
found the solution myself,
apparantly there is one important header, Transfer-Encoding - it should either be removed, or kept as identity, i guess in firefox, it is taken as chunks by default and that was causing the problem.
once i added the below line in server, error flew away.
res.header('Transfer-Encoding', 'identity');
my source the answer to another problem .