fetch-event-source icon indicating copy to clipboard operation
fetch-event-source copied to clipboard

Page Visibility based connection retry is not happening in Error scenario

Open RSMuthu opened this issue 3 years ago • 5 comments
trafficstars

As per the current implementation, whenever the page visibility changes the connection will be disconnected & then reconnect only after the page comes back to visibility (during the time of page hidden, no server call is triggered). But in case of error scenario, even when page is hidden, we are triggering the reconnect request to server.

Sample code to replicate the issue:

fetchEventSource('https://sample.api-service.com/stream', {
    openWhenHidden: false,
    onopen (res) { throw new Error("Dummy Error"); },
    onerror (err) { return 1000; },
}

with the above code executed, the connection keeps failing and tries to reconnect for every 1 second. So far, fine. But when we navigate away from the page (document visibility goes to hidden), even then the server calls are getting triggered in the background.

Need to handle this and make sure that the reconnect calls are not triggers even when page visibility is off.

RSMuthu avatar Apr 24 '22 05:04 RSMuthu

@RoXuS @vishwam Can someone please tell if I can work on this issue myself ?

RSMuthu avatar May 04 '22 10:05 RSMuthu

You can try setting it to true.

fetchEventSource('https://sample.api-service.com/stream', {
    openWhenHidden: true,
    onopen (res) { throw new Error("Dummy Error"); },
    onerror (err) { return 1000; },
}

ReasonDuan avatar Apr 27 '23 15:04 ReasonDuan

on ios safari it seems this still doesn't work if the safari is in the background when the message is received, is there a fix for this

chidera-ugo avatar Nov 01 '23 08:11 chidera-ugo

is there a way to keep fetching in the background when switching tabs? openWhenHidden: true keeps the connection alive but its not contitue fetching?

att1106 avatar Mar 09 '24 10:03 att1106