Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. WakeLock
  4. request()

WakeLock: request() method

Baseline 2025
Newly available

Since ⁨March 2025⁩, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Therequest() method of theWakeLock interface returns aPromise that fulfills with aWakeLockSentinel 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

js
request(type)

Parameters

typeOptional

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 notype parameter is explicitly specified, therequest() method defaults to using thescreen type.

Return value

APromise that resolves with aWakeLockSentinel object.

Exceptions

NotAllowedErrorDOMException

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

  • Use of this feature is blocked by aPermissions Policy.
  • The document is not fully active.
  • The document's visibility state ishidden.
  • TheUser Agent could not acquire platform's wake lock.For example, this might happen if the device is low on battery.

Examples

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

js
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 returnedWakeLockSentinel can be used to check the status of the lock, and/or to manually cancel a held screen wake lock.

Specifications

Specification
Screen Wake Lock API
# the-request-method

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp