WakeLock

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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 can be used to request a lock that prevents device screens from dimming or locking when an application needs to keep running.

This interface, and hence the system wake lock, is exposed through the Navigator.wakeLock property.

Instance methods

request()

Returns a Promise that fulfills with a WakeLockSentinel object if the screen wake lock is granted.

Examples

The following code awaits the request for a WakeLockSentinel object, and continues if the request is granted.

The WakeLock.request() method is wrapped in a try...catch statement to catch cases when the promise might be rejected rejected, such as due to low device power.

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}`);
}

Note that the screen wake lock may be revoked by the device after it has been granted. The returned WakeLockSentinel can be used to check the status of the lock, and/or to manually cancel a held screen wake lock.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android
WakeLock 84 84 126 70 16.4 84 126 60
16.4Does not work in standalone Home Screen Web Apps. See bug 254545.
14.0 84
request 84 84 126 70 16.4 84 126 60
16.4Does not work in standalone Home Screen Web Apps. See bug 254545.
14.0 84

See also

© 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