Detect if Browser Tab is Active or in Background

Hi, Im looking for a solution for my app that needs to query database every few seconds. Id like to disable the database GET query if the browser tab its in is not active / in foreground, etc. Or if theres any other clever method to put it to sleep until there is more user interaction.

Bonus would be if theres a way to detect similar for when it runs on mobile device browser as it tends to just eat data and battery while in the background still.

Hi @Standroid, this topic might be useful for your use case: