A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/en-US/docs/Web/API/WakeLock/request below:

WakeLock: request() method - Web APIs

WakeLock: request() method

Baseline 2025

Newly available

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

The request() method of the WakeLock interface returns a Promise that fulfills with a WakeLockSentinel object if the system screen wake lock is granted.

The screen wake lock prevents device screens from dimming or locking when an application needs to keep running.

Syntax Parameters
type Optional

A string specifying the screen wake lock type, from among the following enumerated types:

screen

Prevents the screen from turning off. Only visible documents can acquire the screen wake lock.

If no type parameter is explicitly specified, the request() method defaults to using the screen type.

Return value

A Promise that resolves with a WakeLockSentinel object.

Exceptions
NotAllowedError DOMException

Thrown when wake lock is not available, which can happen because:

Examples

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

const requestWakeLock = async () => {
  try {
    const wakeLock = await navigator.wakeLock.request("screen");
  } catch (err) {
    // The wake lock request fails - usually system-related, such as low battery.

    console.log(`${err.name}, ${err.message}`);
  }
};

requestWakeLock();

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 See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4