Skip to main content

Command Palette

Search for a command to run...

Screen Wake Lock API In JavaScript

Updated
1 min readView as Markdown
Screen Wake Lock API In JavaScript
S

Hi There, i'm Said Mounaim A passionate Intermediate Full Stack Developer having an experience of building responsive Web applications with JavaScript / React.js / Next.js / Node.js and some other cool libraries and frameworks.

A browser API to prevent the screen from dimming, sleeping or locking automatically,

This feature is very useful for application like timers, voice based application, live score updates, video players ... etc which don't want the screen to be auto locked.

**Note that there are some cases when the lock is removes automatically **

  • When the user navigate away from the tab

  • The user manually locks the screen

let screenLock = await navigator.wakeLock.request('screen');

await lock.release();

**Supported only in Chrome and Edge Currently. **

S

Please note, acc. to MDN, this is experimental technology and is majorly supported by Chrome & its forks and Samsung browser.

We, as developers, have a responsibility to ensure consistent experiences for our users across all supported platforms (in this case browsers). I feel like usage of this tech would hurt it.

I highly recommend providing a fallback like NoSleep.js at least for iOS & Android.

Reference: https://dev.to/mikeesto/the-screen-wake-lock-api-51hp

MDN: https://developer.mozilla.org/en-US/docs/Web/API/WakeLock#browser_compatibility

1

More from this blog

Untitled Publication

15 posts