How to Keep Screens Awake on the Web - Practical Screen Wake Lock API
Last updated on November 3, 2026 am
Auto-sleep is a major annoyance during presentations, recipe reading, and dashboard monitoring. Rather than forcing users to change system-level sleep settings, modern browsers provide a native, zero-install solution: the Screen Wake Lock API.
Requesting the Lock
Acquiring a lock takes a single asynchronous call:
1 | |
HTTPS & Permissions Policy
Because keeping screens on drains battery and generates heat, browsers restrict navigator.wakeLock strictly to Secure Contexts (HTTPS) (with localhost permitted for local development). When embedding the feature inside an iframe, explicitly declare permission:
1 | |
Auto-Reacquire via visibilitychange
Per specification, browsers automatically release active wake locks whenever a user switches tabs, minimizes windows, or locks their device. Without auto-recovery, returning to the page silently leaves the screen unprotected.
Always track user intent separately from the lock state, and reacquire upon return:
1 | |
Supported natively in Chrome 84+, Edge 84+, and Safari 17+, this approach delivers a resilient, battery-safe display lock entirely in front-end JavaScript.
Live demo and interactive implementation: webtools.rustfisher.com