The Page Visibility API

The Page Visibility API is useful for removing listeners (or stopping background processes) from hidden tabs or pages.

You only have to register a visibilitychange listener:

document.addEventListener('visibilitychange', _ => { 
    const state = document.visibilityState;
    console.log('document is: ',state);

Hiding the page / making it visible again prints:

document is:  hidden
document is:  visible    

See it in action:

See you at "Build to last" effectively progressive applications with webstandards only -- the "no frameworks, no migrations" approach, at Munich Airport, Terminal 2 or (online).


Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments