Understanding the Screen Wake Lock API
May 12, 2025
For developers and curious users alike, here's how the magic behind MyScreenOn works.
What is it?
The Screen Wake Lock API provides a way to prevent devices from dimming or locking the screen when an application needs to keep running.
How it works
It's a promise-based API. We request a 'screen' lock, and if the browser grants it, the screen stays on. If the user switches tabs or minimizes the window, the lock is automatically released to save battery.
Why it's better
Older methods involved playing hidden videos or using hacky loops. The native API is cleaner, uses less battery, and respects the user's system state more reliably.