Keep Awake in the Browser: What a Screen Wake Lock Can and Cannot Do
You are halfway through a recipe with both hands covered in flour, or three slides into a presentation, and the display dims. The operating system is doing its job: after a few idle minutes it lowers the brightness and then switches the screen off. "Keep awake" describes both the wish and the browser feature that answers it. This guide covers what the Screen Wake Lock API actually guarantees, where it stops working, and how the Keep Awake tool adds a timer, a fallback and a few optional extras on top.
What the Screen Wake Lock API does
The API is small. A page calls navigator.wakeLock.request("screen") and receives a promise that resolves with a WakeLockSentinel object. While that sentinel is held, the browser asks the operating system to stop dimming or locking the display. Only one lock type exists today: screen. An earlier proposal for a system lock, which would have kept the machine itself running with the display off, was dropped from the specification, so no web page can promise that.
Two rules shape everything else. The page must be served over HTTPS, because the API lives in a secure context. The page must also be visible and fully active: a request from a hidden tab is rejected, and a lock held by a tab that becomes hidden is released automatically. That is why a wake lock behaves more like a lease than a switch. The browser decides when the conditions still hold.
There is no permission prompt. Unlike the camera or location, a wake lock never asks the user for approval, so visibility is the consent model: if you can see the page, the page may ask. The W3C specification is explicit that a user agent treats the request as advisory. A phone in battery saver mode, a laptop on its last few percent, or an operating system policy may ignore the request even though the promise resolved.
Manual actions always win. Pressing the power button, closing the lid, or choosing Sleep releases the lock, and it stays released until the screen is switched on again. Locks also do not stack in a useful way: several requests each return a sentinel, and the display can sleep once all of them are released. Keep Awake stores its sentinel in a ref, listens for the release event, and shows the count in the interruption log.
Why the video hack still matters
Before the API existed, sites kept a screen awake by looping a tiny hidden video. The trick worked because browsers already kept the display on for video playback, but it cost decoding time, memory and battery, and it broke whenever autoplay rules changed. NoSleep.js and similar libraries wrapped that hack. Chrome shipped the Screen Wake Lock API in version 84 in 2020, Safari followed in 16.4 in 2023, and Firefox in 126 in 2024, which is why MDN now marks the feature as Baseline 2025.
The old approach has not disappeared, and it still has a use: in browsers or embedded views where navigator.wakeLock is missing, or where the request is refused because of power policy, a video fallback can hold the display where the API cannot. Keep Awake tries the lock first. If the request fails, it offers a button labelled "Loop a silent video", starts a muted, looping video element, and keeps the same countdown running.
That fallback needs a click on purpose. Browsers block autoplay with sound, and many block muted autoplay as well unless a user gesture has happened. Starting the video from a button keeps the behaviour predictable and keeps the toast messages honest: the page never claims a lock it did not get.
The limits you cannot code around
The first limit is the document itself. A hidden tab has no wake lock, no matter how the page was written. Switching to another application, minimising the window, or locking the phone releases the lock, and a page cannot request a new one while it is hidden. Auto re-acquire in Keep Awake handles the return: the tool listens for visibilitychange, checks the capability again, and asks for a fresh sentinel when the tab is visible.
The second limit is power policy. The specification allows the browser to ignore a request when the battery is low or a power-saving mode is active. A resolved promise is therefore not a guarantee for the whole session. Coverage in this tool measures the difference: it compares the seconds the lock was actually held with the seconds that were requested, and reports the share as a percentage.
The third limit is the operating system. A wake lock controls the display sleep timer, not the system sleep timer. If the machine is set to sleep after ten minutes of idle time, the screen may stay lit for the length of the session and the computer may still suspend on its own schedule. Closing the lid ends everything.
| Browser | First version with the screen wake lock | Notes |
|---|---|---|
| Chrome (desktop and Android) | 84 | Supported since 2020 |
| Edge (desktop) | 84 | Same Chromium implementation |
| Firefox (desktop and Android) | 126 | Supported since 2024 |
| Safari (macOS) | 16.4 | Supported since 2023 |
| Safari (iOS) | 16.4 | Partial range 16.4 to 18.4; not available in Home Screen web apps |
| Samsung Internet | 14.0 | Chromium-based |
Embedded pages add one more layer. Inside an iframe the screen-wake-lock permission is controlled by Permissions Policy, and a third-party frame needs an explicit allow="screen-wake-lock" attribute. A page can also disable the feature entirely with a response header. Keep Awake runs as a top-level page, so this only matters if you embed it somewhere.
How a session runs in the tool
The duration controls are built around the way people actually ask for this. Six presets cover 15 minutes, 30 minutes, 1 hour, 2 hours, 4 hours and 8 hours. A clock target accepts a time such as 14:30 and holds the lock until that moment, rolling over to the next day when the time has already passed. A custom field takes a number and a unit, seconds, minutes or hours, with a ceiling of 43,200 minutes, which is 30 days. The Infinity option skips the end time entirely and keeps the lock until you stop it.
Starting a session is one press. Keep Awake requests the lock, records the start and the target, switches the status from Idle to Active, and begins drawing the ring. The same button becomes Let Sleep, which releases the sentinel and records the held time in the local statistics. A timed session ends on its own and can play a short chime or raise a desktop notification, if you enabled them.
The tool also survives a refresh. The session is written to localStorage, so a reload or an accidental tab close leaves a prompt offering to resume with the remaining time. An infinity session is offered back for one day, and a timed session only while it still has time left. Auto re-acquire is a separate checkbox: it re-requests the lock after every visibility change, which is what makes a long session survive a quick look at another tab.
A typical run looks like this:
- Pick a preset, a clock target, a custom duration or Infinity.
- Decide whether Pomodoro, a sleep sound or a notification should be part of the session.
- Press Keep Awake, leave the tab visible, and read the ring when you need the remaining time.
Pomodoro, noise and screen modes
Pomodoro turns the timer into a cycle: 25 minutes of focus, then a 5 minute break, repeated until you stop. The switch is announced with a toast, and the checkbox is disabled while a session is active so the pattern does not change halfway through. This is useful when the screen has to stay on for a work block rather than for a single task.
The sound panel generates noise in the browser with the Web Audio API. White, pink and brown noise are synthesised directly, while Rain and Fan layer filters over the noise to soften the high end. Five options in total, plus Off. The volume slider runs from 0 to 100, and an auto-stop can end the sound after 15, 30 or 60 minutes while the wake lock keeps going. A separate checkbox keeps the noise playing when the stealth window opens.
The screen panel holds the display modes. Stealth opens a black window with only the clock, which suits a dark room or an overnight session. Fullscreen puts the tool card on the whole display, with its own scroll so the settings below the fold stay reachable. The mini window uses Document Picture-in-Picture and is available in Chromium browsers only, so the button is hidden elsewhere. Five palettes, a free accent colour, a dark card style and a background image complete the look; the image is capped at 8 MB and redrawn at a maximum edge of 1920 pixels before it is used.
Reading the countdown and the log
The ring is the main display, but four numbers sit under it. Time remaining counts down to the end of the session. Elapsed counts up from the start. Coverage shows the percentage of the requested time the lock was actually held. Interruptions counts the times the browser released the lock, and the usage panel lists the last timestamp. The end time is printed in local clock format, so a session started at 09:40 for two hours reads as ending at 11:40.
The timer prints as HH:MM:SS, and hours are not capped at two digits, which matters for an 8-hour preset. Statistics live in localStorage rather than on a server: minutes held today, minutes held over the last seven days, and the number of active days. Day buckets older than 60 days are dropped to keep the file small. Clearing site data removes the history, and a private window usually starts with nothing.
None of these numbers leave the device. There is no account, no sync and no analytics call in the tool, so the usage panel is a local record rather than a dashboard someone else can read.
When to keep the screen awake, and when not to
The API was built for tasks where the user has to keep looking. Following a recipe, reading an ebook, navigating a map, presenting slides, scanning a barcode or a QR code, running a kiosk, or following a workout all qualify. Google's own guide lists the same set and notes that the Betty Crocker cooking site measured a 300% increase in purchase intent indicators after adding the lock to its recipe pages.
The opposite cases matter just as much. If the user is listening to audio, the screen can sleep. If a long download or an upload is running, background fetch or background sync is the right tool, not a lit display. If the device is on battery and the task does not require looking, letting the screen sleep saves power, and the specification warns that a wake lock increases consumption. A session that holds the display for hours on a laptop unplugged will drain the battery faster than the same work with the screen off.
The practical rule: lock the screen when a person must see it, release it when they do not. Keep Awake makes the release easy by bounding every session, by ending it with a chime or a notification, and by showing how much of the requested time the lock actually covered.
Frequently Asked Questions
Does Keep Awake stop my computer from going to sleep?
No. A screen wake lock keeps the display from dimming or locking, while the operating system sleep timer is a separate setting. The machine can still suspend on its own schedule, and closing the lid or choosing Sleep ends the session immediately.
Why does the lock drop when I switch tabs?
Browsers release a wake lock when the document becomes hidden, because a background tab cannot justify keeping the display on. Keep Awake records the interruption and, with Auto re-acquire enabled, requests a fresh lock as soon as the tab is visible again.
Which browsers support the wake lock?
Chrome and Edge from version 84, Firefox from 126, Safari from 16.4 on macOS, and Samsung Internet from 14. Safari on iOS has partial support and does not provide the lock in Home Screen web apps, so the page should be kept in a normal tab there.
Does the tool need an internet connection?
Only to load the page. After that the timer, the noise, the image processing and the statistics run locally, and a session continues if the connection drops. Nothing is sent to a server during the session.
What happens if the browser refuses the lock?
The tool shows the refusal and offers the video fallback. One click on "Loop a silent video" starts a hidden looping video that keeps the display awake, and the countdown continues as before. The fallback uses more CPU than the lock.
Can I keep the screen on for eight hours or longer?
Yes. The 8-hour preset covers a working day, and a custom duration reaches 43,200 minutes, which is 30 days. Long sessions depend on the device staying plugged in and on the operating system not suspending on its own timer.
How does Pomodoro mode work here?
Enabling Pomodoro alternates 25 minutes of focus with a 5 minute break, announced by a toast at each switch, and the wake lock stays on through both phases. The setting is locked while a session is running.
Is anything uploaded or tracked?
No. The page makes no request during a session, the noise is generated in the browser, and the saved session and usage counters sit in localStorage on your device. Clearing site data deletes them.
Ho Chi Minh City, Vietnam · SO reputation 7996 · Badges: 17🥇65🥈89🥉 · SO member since 2013