Skip to content
Open source · v1.0.0

@awaketab/wake: the honest wake lock library

An open-source Screen Wake Lock library with seven honest states, a tiny video fallback and denial advice. The maintained NoSleep.js replacement.

Install

terminal
npm install @awaketab/wake
main.js
import { createWakeLock } from '@awaketab/wake'; const lock = createWakeLock();lock.on('change', ({ from, to, reason, advice }) => {  pill.textContent = to;            // one of the seven states  hint.textContent = advice ?? '';  // e.g. 'iframe_no_allow', 'hidden_document'});start.addEventListener('click', () => lock.request()); // a tap allows the fallbackstop.addEventListener('click', () => lock.release());

Seven honest states

The same states and pill copy as the AwakeTab tool.

idleWhat the pill says: Ready
requestingWhat the pill says: Starting…
heldWhat the pill says: Screen awake
lostWhat the pill says: Paused — tab hidden
deniedWhat the pill says: Blocked — here's the fix
unsupportedWhat the pill says: Tap to use the fallback
fallbackWhat the pill says: Awake via video fallback

@awaketab/wake vs NoSleep.js

Last release@awaketab/wake: Maintained; semverNoSleep.js: 16 December 2020
Native Wake Lock@awaketab/wake: Yes, firstNoSleep.js: Yes (when present)
State reporting@awaketab/wake: Seven states + change events with reason and adviceNoSleep.js: isEnabled boolean
Denial diagnosis@awaketab/wake: classifyDenial() advice codesNoSleep.js: None
Fallback@awaketab/wake: Inlined 1-frame video, gesture-aware, pauses when hiddenNoSleep.js: Looping video, always on
Size (gzip)@awaketab/wake: ≤ 3.4 KB, fallback includedNoSleep.js: ≈ 3.2 KB
TypeScript · SSR@awaketab/wake: Native · inert on the serverNoSleep.js: Community typings · no
Adapters@awaketab/wake: React, Preact, Vue (< 400 B each)NoSleep.js: No