The Page Visibility API provides events you can watch for to know when a document becomes visible or hidden.
Provides a block that notifies you about state changes of the visibility of the page.
Example scenario: you are playing a video and want to pause it if the user changes tabs.