JavaScript Navigator wakeLock Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline

What You’ll Learn

navigator.wakeLock returns a WakeLock object from the Screen Wake Lock API. Learn how to request a screen lock, release it, handle failures, re-acquire after tab switches, five examples, and try-it labs.

01

Kind

Read-only property

02

Returns

WakeLock

03

Baseline

Newly available

04

Context

Secure (HTTPS)

05

Key method

request("screen")

06

Handle

WakeLockSentinel

Introduction

Phones and laptops often dim or lock the screen to save battery. That is great most of the time — but terrible while you follow a recipe, read a map, present slides, or scan a QR code.

navigator.wakeLock is the entry point to the Screen Wake Lock API. While a screen wake lock is active, the browser tries to prevent dimming, turning the screen off, or showing a screensaver.

💡
Visible documents only

MDN: only visible (active) documents can acquire the screen wake lock. If the user switches tabs or minimizes the window, the lock is often released automatically.

Understanding the wakeLock Property

Think of navigator.wakeLock as a gate to one main action: request("screen"). That Promise resolves to a WakeLockSentinel you keep around so you can release the lock later.

  • WakeLock — object returned by the property.
  • request("screen") — ask for a screen wake lock (default type is also screen).
  • WakeLockSentinel — handle for the granted lock; call release().
  • release event — fires when the lock ends (manual or system).
  • Secure context — HTTPS / localhost required.
  • Permissions Policy — may be gated by screen-wake-lock.

📝 Syntax

General form of the property:

JavaScript
navigator.wakeLock

Value

  • A WakeLock object used to request screen wake locks.

Common patterns

JavaScript
// Feature-detect:
if ("wakeLock" in navigator) {
  // Supported
}

// Request (MDN-style):
let sentinel = null;
try {
  sentinel = await navigator.wakeLock.request("screen");
  console.log("Wake Lock is active!");
} catch (err) {
  console.log(err.name + ", " + err.message);
}

// Release later:
if (sentinel) {
  await sentinel.release();
  sentinel = null;
}

⚡ Quick Reference

GoalCode
Get WakeLocknavigator.wakeLock
Feature detect"wakeLock" in navigator
Request screen lockawait navigator.wakeLock.request("screen")
Release lockawait sentinel.release()
Listen for endsentinel.addEventListener("release", …)
Secure context?window.isSecureContext
Page visible?document.visibilityState === "visible"

🔍 At a Glance

Four facts to remember about navigator.wakeLock.

Returns
WakeLock

Screen lock API

Status
Baseline

Newly available

Context
HTTPS

Secure required

Type
"screen"

Keep display on

📋 Default Screen Timeout vs Screen Wake Lock

Default device behaviorWith Screen Wake Lock
After idle timeScreen dims / locksBrowser tries to keep screen on
BatterySaved by timeoutUses more power — use only when needed
Tab hiddenN/ALock usually released; re-request when visible
User controlSystem settingsYour UI should offer an Off control

Examples Gallery

Examples follow MDN Screen Wake Lock patterns. Prefer Try It Yourself on HTTPS with the tab visible — requests fail when the document is hidden or the battery policy blocks them.

📚 Getting Started

Detect the API and request a screen wake lock.

Example 1 — Feature Detection

MDN-style support check before enabling a Keep Awake button.

JavaScript
const lines = [
  "wakeLock: " + ("wakeLock" in navigator ? "available" : "missing"),
  "isSecureContext: " + window.isSecureContext
];
console.log(lines.join("\n"));
Try It Yourself

How It Works

If missing, disable the Keep Awake control and explain that the browser does not support the API.

Example 2 — Request a Screen Lock

MDN async request with try...catch.

JavaScript
async function requestWakeLock() {
  if (!("wakeLock" in navigator)) {
    return "wakeLock not supported";
  }
  try {
    const sentinel = await navigator.wakeLock.request("screen");
    return "Wake Lock is active! type=" + sentinel.type;
  } catch (err) {
    return err.name + ", " + err.message;
  }
}

requestWakeLock().then((msg) => console.log(msg));
Try It Yourself

How It Works

Store the sentinel in a variable so you can release it later and listen for automatic release.

📈 Practical Patterns

Release the lock, listen for release, and re-request when the tab becomes visible again.

Example 3 — Release the Lock

Let the user turn Keep Awake off.

JavaScript
async function demoRelease() {
  if (!("wakeLock" in navigator)) {
    return "wakeLock not supported";
  }
  let sentinel;
  try {
    sentinel = await navigator.wakeLock.request("screen");
  } catch (err) {
    return "request failed: " + err.name;
  }
  await sentinel.release();
  return "Wake Lock released. released=" + sentinel.released;
}

demoRelease().then((msg) => console.log(msg));
Try It Yourself

How It Works

After release, the sentinel cannot be reused — request a new one if you need the lock again.

Example 4 — Listen for release

Update UI when the system or your code ends the lock.

JavaScript
async function demoReleaseEvent() {
  if (!("wakeLock" in navigator)) {
    return "wakeLock not supported";
  }
  try {
    const sentinel = await navigator.wakeLock.request("screen");
    sentinel.addEventListener("release", () => {
      console.log("Wake Lock has been released");
    });
    await sentinel.release();
    return "Requested, then released — check the release log above.";
  } catch (err) {
    return err.name + ", " + err.message;
  }
}

demoReleaseEvent().then((msg) => console.log(msg));
Try It Yourself

How It Works

The release event also fires when the user hides the tab — keep your status text in sync.

Example 5 — Re-acquire on Visibility

Common pattern: when the page becomes visible again, request a new lock if the user still wants Keep Awake.

JavaScript
let sentinel = null;
let wantLock = true; // user toggled Keep Awake on

async function ensureWakeLock() {
  if (!wantLock || !("wakeLock" in navigator)) return;
  if (document.visibilityState !== "visible") return;
  try {
    sentinel = await navigator.wakeLock.request("screen");
    console.log("Wake Lock re-acquired");
  } catch (err) {
    console.log("Could not acquire: " + err.name);
  }
}

document.addEventListener("visibilitychange", () => {
  if (document.visibilityState === "visible") {
    ensureWakeLock();
  } else {
    console.log("Page hidden — lock may be released by the system");
  }
});

console.log("visibilityState: " + document.visibilityState);
ensureWakeLock();
Try It Yourself

How It Works

Wake locks do not survive tab switches forever. Re-request when the document is visible again if the feature should stay on.

🚀 Common Use Cases

  • Recipes & cooking timers — keep the screen readable while hands are busy.
  • Maps / navigation — avoid dimming mid-route.
  • Presentations — keep slides visible for an audience.
  • Ebooks / karaoke / workouts — continuous viewing without taps.
  • QR / barcode scanning — camera UIs that need a lit screen.

🧠 How navigator.wakeLock Works

1

Visible page on HTTPS

Feature-detect and ensure the document is visible.

Ready
2

request("screen")

Browser asks the platform for a screen wake lock.

Request
3

Hold a WakeLockSentinel

Keep a reference; listen for release; update UI.

Active
4

Release or re-acquire

Call release(), or request again when the tab returns.

📝 Notes

  • Baseline Newly available (MDN) — not Deprecated, Experimental, or Non-standard.
  • Secure context required (HTTPS / localhost).
  • Returns WakeLock; main method is request("screen")WakeLockSentinel.
  • Only visible documents can acquire the lock; wrap requests in try...catch.
  • Related: webdriver, userActivation, virtualKeyboard, Window.

Modern Browser Support

navigator.wakeLock is Baseline Newly available for the Screen Wake Lock API. It requires a secure context. Always feature-detect, request only while the page is visible, and handle refusal (battery / policy) gracefully.

Baseline · Newly available

Navigator.wakeLock

WakeLock entry point — request a screen lock, hold a WakeLockSentinel, release when done.

Modern Newly available
Google Chrome Screen Wake Lock · Desktop & Mobile
Full support
Microsoft Edge Screen Wake Lock · Chromium
Full support
Opera Screen Wake Lock · Modern versions
Full support
Apple Safari Screen Wake Lock · check version / platform
Full support
Mozilla Firefox Screen Wake Lock · check version
Full support
Internet Explorer No wakeLock support
Unavailable
wakeLock Strong

Bottom line: Detect wakeLock, call request("screen") from a visible tab on HTTPS, listen for release, and re-acquire on visibilitychange when Keep Awake stays on.

Conclusion

navigator.wakeLock is the Baseline entry point for keeping the screen awake when usability needs it. Request a screen lock on a visible HTTPS page, hold the sentinel, release when done, and re-acquire after visibility changes.

Continue with webdriver, userActivation, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect "wakeLock" in navigator
  • Use HTTPS / localhost
  • Wrap request() in try...catch
  • Show lock status and an Off control
  • Re-request on visibilitychange when needed

❌ Don’t

  • Leave Keep Awake on with no user control
  • Expect locks to survive hidden tabs forever
  • Ignore low-battery / NotAllowedError failures
  • Reuse a sentinel after release()
  • Assign to navigator.wakeLock

Key Takeaways

Knowledge Unlocked

Five things to remember about wakeLock

Baseline screen lock — request, hold sentinel, release, re-acquire when visible.

5
Core concepts
02

Request

request("screen")

API
🔒 03

Context

secure HTTPS

Required
👁 04

Visible

document must show

Rule
🎯 05

Handle

WakeLockSentinel

Release

❓ Frequently Asked Questions

A WakeLock object for the Screen Wake Lock API. Call wakeLock.request("screen") to get a WakeLockSentinel that helps keep the screen from dimming or locking while your visible page needs to stay on.
No. MDN marks it Baseline Newly available. It is not Deprecated, Experimental, or Non-standard. It does require a secure context (HTTPS / localhost).
Yes. MDN lists it as a secure-context feature (HTTPS or localhost) in supporting browsers.
Common reasons: the document is hidden / not fully active, Permissions Policy blocks screen-wake-lock, low battery / power save, or the platform cannot grant the lock. Wrap request() in try/catch.
The object returned when a lock is granted. Use release() to free it manually, listen for the release event, and check the released property. After release, request a new lock if you still need one.
No. Use wake lock only when it helps usability (recipes, maps, presentations, ebooks). Show UI status and let the user turn it off.
Did you know?

A screen wake lock is different from preventing a laptop from sleeping entirely. It targets the display (dim / lock / screensaver) for visible pages — not a guarantee that background CPU work or downloads will keep running forever.

Learn webdriver Next

Baseline boolean — detect WebDriver automation for test code paths.

webdriver →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful