How Websites Keep Your Screen Awake: Screen Wake Lock API
A website keeps your screen from sleeping by calling the Screen Wake Lock API: one line of JavaScript that asks the browser, which in turn asks the operating system, to leave the display on. The browser only grants it while the page is visible, and it takes the lock back the moment you switch tabs or the battery runs low. Here's how that works, the rules behind it, and how to check it on your own machine.
What the Screen Wake Lock API does
Your phone or laptop turns its screen off after a few minutes without input. That's the right call most of the time and the wrong one when you're following a recipe, reading sheet music, scanning a QR code, or presenting. The W3C specification lists those exact cases as the reason the API exists.
The whole thing is one call:
const lock = await navigator.wakeLock.request('screen');
If the browser agrees, it asks the operating system to keep the display on and hands the page an object representing the lock. The page can release it later with lock.release(), or the browser can take it away.
There is only one kind of lock: screen. An early draft also had a system lock that would have kept the CPU running with the screen off. Chrome's team says they aren't proceeding with it, and it's gone from the spec.
What sites did before it existed
Before browsers shipped this, sites that needed the screen on resorted to tricks. The best known was playing a tiny, silent video on a loop somewhere on the page, because devices don't sleep during video playback. Google's Chrome documentation calls these workarounds "hacky and potentially power-hungry."
NãoDorme, the keep-awake page I tested for this article, used to carry that fallback. It has since dropped it: when the browser has no API or refuses the request, the page now says so and tells you to change your system's screen timeout.
The rules browsers enforce
A screen that never turns off is a battery and security problem, so the API comes with conditions. These come from the spec and from browser vendors' own notes.
| Rule | What it means for you |
|---|---|
| Secure pages only | The API exists only on HTTPS pages. |
| Visible pages only | A hidden tab can't get a lock, and a lock is released when its page becomes hidden. |
| No permission prompt | Because the lock dies with visibility, no browser asks you first. A browser can still say no for its own reasons. |
| Safari wants a gesture | WebKit requires a tap or click for a page's first request. After that, the page can re-request without one. |
| The browser can revoke it | The spec allows release at any time, naming low battery, power-saving modes, and systems that dim the screen based on user presence. |
| Embedded content needs approval | A third-party iframe can't use it unless the host page allows it through Permissions Policy. |
One more rule is easy to miss: the spec says a screen wake lock must not apply after you manually switch the screen off. It's there to stop the automatic timeout, not to override you.
Which browsers support it
According to MDN's compatibility table:
| Browser | Supported since |
|---|---|
| Chrome and Edge (desktop and Android) | Version 84 |
| Firefox | Version 126 |
| Safari on Mac | Version 16.4 |
| Safari on iPhone and iPad | iOS 16.4, with one catch |
The catch: before iOS 18.4, the API didn't work in sites launched from a Home Screen icon. It worked in a regular Safari tab and failed in the same site saved to the Home Screen, which confused a lot of people.
Where it fails in real life
These are the cases that explain most "the site said it would keep my screen on and it didn't" complaints.
You switched tabs. The lock is released as soon as the page is hidden, and it doesn't come back on its own. A well-built site listens for the page becoming visible again and asks for a new lock. A site that skips that step works until your first tab switch and never again.
Something covered the window. Minimizing does it for sure. A full-screen app sitting on top of the browser tends to do it too. I haven't tested that in every browser, so treat any covered tab as a lost lock.
A power-saving mode was on. The spec lets browsers ignore requests when the battery is low or the device is in a power-saving mode.
The page couldn't tell. This one surprised me. The spec's privacy section says that when the operating system refuses the lock, the page can still see a successful request, because a visible failure would leak the fact that your battery is low. A site may sincerely believe it's holding a lock that isn't there.
The browser blocked it outright. One browser I tested in, an embedded browser inside another app, had the permission set to denied. The request failed with NotAllowedError: Wake Lock permission request denied. The page I was testing caught the refusal: it showed a notice saying the browser didn't allow keeping the screen awake, and its status changed to "Active (animation only)." Not every site does that, so an animation on screen tells you nothing by itself about whether a lock is held.
An old browser. Anything older than the versions in the table has no API at all.
Does it keep the whole computer awake, or just the screen?
By the standard, just the screen. In practice it's usually both, because most systems don't sleep while something is holding the display on.
Chromium, the engine behind Chrome and Edge, says so in its source code: the comment on its display lock reads that it "also has the side effect of preventing the system from sleeping." Chrome's documentation shows the same thing from the outside, with macOS Activity Monitor reporting that Chrome is keeping the system awake while a lock is active.
Two limits apply. A sleep you trigger yourself, such as closing the lid or pressing the power button, isn't blocked. And none of this holds once the tab is hidden, so a wake lock is no way to keep a download running overnight in a background tab.
Check it yourself
You can watch a lock being granted and taken away in about a minute, in Chrome or Edge on a computer.
- Open any HTTPS page and open DevTools (F12), then the Console.
- Ask what the browser thinks of the permission:
(await navigator.permissions.query({ name: 'screen-wake-lock' })).state
- Request a lock and log its release:
const lock = await navigator.wakeLock.request('screen');
lock.addEventListener('release', () => console.log('released'));
- Switch to another tab, then come back. Per the spec, you should find
releasedin the console, andlock.releasedshould now betrue.
To see it from the operating system's side, run pmset -g assertions in Terminal on a Mac, or powercfg /requests in an administrator Terminal on Windows. Both list what is currently asking to keep the display on.
A working example to poke at
If you'd rather not type code, a keep-awake page shows the same behavior. On NãoDorme, clicking one of the eight effects triggers the request, which also satisfies Safari's gesture rule. Its source asks for a new lock whenever the tab becomes visible again and releases the lock when you exit or when the duration you picked runs out.
Two details I noticed using it. The duration defaults to no limit, so the lock is held until you leave unless you choose 15 minutes, 30 minutes, 1 hour, or 2 hours first. And when a timed session ends, the effect closes and you're back on the site's home page with the device's normal sleep timer running again.
The honest test is the simple one. Start an effect, leave the device untouched for longer than its usual screen timeout, and see whether the display is still on.
For developers: a short checklist
- Feature-detect with
'wakeLock' in navigatorbefore calling anything. - Make the first request inside a click or tap handler so Safari accepts it.
- Wrap the request in
try...catch. A rejection is normal, not exceptional. - Keep a reference to the lock and listen for its
releaseevent. - Re-request on
visibilitychangewhen the page is visible again. - Release the lock when the task is done. Don't hold it for the life of the page.
- Show the user whether the lock is active. MDN recommends this, and it's the only way they can know.
- Don't promise the screen will stay on. The browser has the last word.


