Wake Lock

The Wake Lock API allows Web applications to prevent the resource such as the screen or system from becoming unavailable as long as the application holds a lock for that resource. The purpose of the API is to let the user or the application to complete the ongoing long activity - like navigation or reading - uninterrupted.

The only available implementation, available behind an "Experimental Web Platform Features" flag in Google Chrome on desktop, is just a boolean flag controllable by the application, based on the previous version of the specification. It is now considered too open for abuse and is lacking user consent, so the recent specification draft (published June 2017) proposes more explicit approach. It is not implemented by any vendor, yet.

API glimpse

Newer specification

navigator.getWakeLock('screen')
Requests a wake lock managing object on the resource specified, such as screen or system. Returns a Promise with the lock managing object.
lockRequest = lock.createRequest()
Activates the wake lock on the previously acquired managing object.
lockRequest.cancel()
Releases the existing lock.

Older specification

screen.keepAwake = true
The property allowing to acquire a screen wake lock when set to true and release it when set to false.

Live Demo

Wake Lock status is unknown (not supported).

  • function printStatus() {
      document.getElementById("status").innerHTML = screen.keepAwake
        ? "enabled"
        : "disabled";
    }
    
    function toggle() {
      if ("keepAwake" in screen) {
        screen.keepAwake = !screen.keepAwake;
        printStatus();
      }
    }
    
    if ("keepAwake" in screen) {
      printStatus();
    }
  • <p>Wake Lock status is <b id="status">unknown (not supported)</b>.</p>
    <p><button class="btn btn-default" onclick="toggle()">Toggle</button></p>

Resources