Screen Wake Lock API

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2021 May 23 16:17
Editor
Edited
Edited
2023 Apr 28 16:0
Refs
Refs
// The wake lock sentinel. let wakeLock = null; // Function that attempts to request a screen wake lock. const requestWakeLock = async () => { try { wakeLock = await navigator.wakeLock.request(); wakeLock.addEventListener('release', () => { console.log('Screen Wake Lock released:', wakeLock.released); }); console.log('Screen Wake Lock released:', wakeLock.released); } catch (err) { console.error(`${err.name}, ${err.message}`); } }; // Request a screen wake lock… await requestWakeLock(); // …and release it again after 5s. window.setTimeout(() => { wakeLock.release(); wakeLock = null; }, 5000);
 
 
 
 
Screen Wake Lock Demo
Stay awake with the Screen Wake Lock API
To avoid draining the battery, most devices will quickly fall asleep when left idle. While this is fine most of the time, there are some applications that need to keep the screen awake in order to complete some work.
Stay awake with the Screen Wake Lock API
 
 

Recommendations