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
2
3
4
5
6
7
8
9
10
let wakeLock = null;

async function lockScreen() {
try {
wakeLock = await navigator.wakeLock.request('screen');
wakeLock.addEventListener('release', () => console.log('Wake Lock released'));
} catch (err) {
console.error(`${err.name}: ${err.message}`);
}
}

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
<iframe src="https://example.com" allow="screen-wake-lock"></iframe>

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
2
3
4
5
document.addEventListener('visibilitychange', async () => {
if (wakeLock !== null && document.visibilityState === 'visible') {
await lockScreen();
}
});

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


How to Keep Screens Awake on the Web - Practical Screen Wake Lock API
https://en.rustfisher.com/web/keep-screen-awake-on-the-web/
Author
Rust Fisher
Posted on
November 3, 2026
Licensed under