This is related to the following:
Safari 9.1 for El Capitan
Safari 10 for Sierra
Does anyone know what is Safari doing in the JavaScript engine with respect to setTimeout() when the browser or the tab loses focus (mainly, is minimized)?
I have created a simple JavaScript web application that I load in Safari that calls JavaScript setTimeout() that passes another function to be executed after the timeout value. The function prints the date/time to the console, then calls setTimeout() with the same timeout value.
If the Safari tab loses focus or the browser is minimized, after some time it seems Safari stops executing the setTimeout, and the subsequent function to be called, and until focus is returned, no function execution occurs. It's as if the event loop stops processing.
NOTE: No function calls are lost, they are only paused, and restarted when the browser regains focus.
I do not notice this in Firefox, Chrome or IE11.
Main reason this question is being posed is that the problem is mainly observed with a web application I am maintaining that uses CometD for communication back to the server. CometD library is using setTimeout to execute a request back to the server every 30 seconds. If the browser running the application is minimized, it seems CometD stops communicating with the server until the browser is maximized again.