'Continue to receive server sent event after leaving and returning to a page

I have an EventSource that does nothing initially:

var source = new EventSource('{{do_nothing}}');

Then I trigger something in my flask backend and it changes my 'do_nothing' to a server sent event:

var source = new EventSource('/my_event');

and this server sent event will start sending (yielding) data where my source will pick it up and do stuff:

source.onmessage = function(event) { get(event.data) do stuff }

however if I leave the webpage; and return to the web page again, or open up the web page in another browser the event is no longer occurring on the newly opened page.

How do I make it so if I return to the same page that I will continue to get the output of the server sent event until the server sent event completes itself?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source