W3cubDocs

/Web APIs

WakeLock

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The WakeLock interface of the Screen Wake Lock API prevents device screens from dimming or locking when an application needs to keep running.

The system wake lock is exposed through the global Navigator.wakeLock property.

Instance methods

request()

Requests a WakeLockSentinel object, which returns a Promise that resolves with a WakeLockSentinel object.

Examples

The following asynchronous function requests a WakeLockSentinel object. The WakeLock.request() method is wrapped in a try...catch statement to account for if the browser refuses the request for any reason.

js

try {
  const wakeLock = await navigator.wakeLock.request("screen");
} catch (err) {
  // the wake lock request fails - usually system related, such being low on battery
  console.log(`${err.name}, ${err.message}`);
}

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
WakeLock 84 84 No No 70 16.4 84 84 No 60 16.4 14.0
request 84 84 No No 70 16.4 84 84 No 60 16.4 14.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WakeLock