Skip to main content

Lesson 9 of 9

Page Visibility & Screen APIs

The Page Visibility API detects when a user switches away from your tab - allowing you to pause videos, stop animations, save battery, and track actual time spent on page. The Screen Wake Lock API prevents the screen from sleeping during presentations, video playback, or recipe cooking steps.

10 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Visibility & Screen APIs

  • document.hidden - Boolean. true when tab is hidden (user switched away).
  • visibilitychange event - Fires when tab visibility changes. Use to pause/resume media.
  • Pause video when tab hidden - Save bandwidth and battery. Resume when user returns.
  • Stop animations when hidden - CSS animations continue even in hidden tabs. Use visibility API to pause JavaScript animations.
  • Track actual time on page - Start a timer when visible, pause when hidden. More accurate than page load duration.
  • Screen Wake Lock - navigator.wakeLock.request('screen') keeps screen awake. Great for recipe apps, presentations, music players.
  • Release wake lock - await sentinel.release() when no longer needed (e.g., video ends).
Diagram
Loading diagramโ€ฆ

Pause animations and network polling when browser tabs are hidden to save power

Module 8 - Knowledge Check

Module 8 - Knowledge Check
Question 1 of 5

What is the key difference between localStorage and sessionStorage?

Key Takeaways

  • The Page Visibility API detects when a user switches away from your tab - allowing you to pause videos, stop animations, save battery, and track actual time spent on page.
  • document.hidden - Boolean. true when tab is hidden (user switched away).
  • visibilitychange event - Fires when tab visibility changes. Use to pause/resume media.
  • Pause video when tab hidden - Save bandwidth and battery. Resume when user returns.

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/9 done