files/en-us/web/api/wakelock/request/index.md
{{APIRef("Screen Wake Lock API")}}{{SecureContext_Header}}
The request() method of the {{domxref("WakeLock")}} interface returns a {{jsxref("Promise")}} that fulfills with a {{domxref("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.
request(type)
type {{optional_inline}}
screen
If no type parameter is explicitly specified, the request() method defaults to using the screen type.
A {{jsxref("Promise")}} that resolves with a {{domxref("WakeLockSentinel")}} object.
NotAllowedError {{domxref("DOMException")}}
hidden.The following asynchronous function requests a {{domxref("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 {{domxref("WakeLockSentinel")}} can be used to check the status of the lock, and/or to manually cancel a held screen wake lock.
{{Specifications}}
{{Compat}}