Skip to content
C.W.K.
Stream
Lesson 03 of 04 · published

Wake Lock Fails Soft

~10 min · wake-lock, progressive-enhancement, browser-api, failure

Level 0Dry Nib
0 XP0/36 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete
"Progressive enhancement may improve attention; it may not become an entrance fee."

The scene beside paper

A dimmed screen interrupts copying, so requesting a screen Wake Lock is a useful courtesy. It is still a browser capability that may be unsupported, denied, released when hidden, or revoked by the system.

Make it interface state

Request it only during an active writing view, catch failures, release it on exit, and reacquire after visibility returns when appropriate. Surface a quiet status rather than blocking the passage.

When help becomes interference

Treating Wake Lock as required breaks the app on unsupported devices. Retrying without visibility checks wastes power. Forgetting release turns a focus aid into a battery leak.

Focus invariant. Progressive enhancement may improve attention; it may not become an entrance fee.

Test from the hand outward

Do not judge “Wake Lock Fails Soft” from a browser screenshot alone. Put a pen in one hand and touch the screen only when necessary; trace type size, button distance, scrolling, rotation, and failure. If one enhancement is denied, the passage must remain readable and transcribed state writable.

Verify it

Test supported, unsupported, denied, hidden, visible-again, and explicit-exit paths. Include a small phone, large tablet, bright and dark rooms, and keyboard-only use. Count how often the feature steals the eyes from the pen instead of merely admiring its appearance.

Disappearing still needs state

Hiding chrome, acquiring wakefulness, and attaching a photo must all be reversible. Exit, release, deletion, and failure copy let technology disappear while remaining able to explain itself when needed.

Guard the acquire-exit race

An exit can happen while navigator.wakeLock.request is still pending. Record desired state and a request token; if the promise resolves after exit or after a newer request, release that newly acquired sentinel immediately instead of publishing it as active.

Cleanup must identify the sentinel it owns so an older release event cannot clear a newer lock.

Code

Ask for wakefulness politely·javascript
let sentinel = null;
let desiredActive = false;
let requestToken = 0;

export async function setWritingAwake(active) {
  desiredActive = active;
  const token = ++requestToken;

  if (!active) {
    const held = sentinel;
    sentinel = null;
    await held?.release();
    return { active: false, supported: "wakeLock" in navigator };
  }
  if (!("wakeLock" in navigator)) {
    return { active: false, supported: false };
  }

  try {
    const acquired = await navigator.wakeLock.request("screen");
    if (!desiredActive || token !== requestToken) {
      await acquired.release();
      return { active: false, supported: true };
    }
    sentinel = acquired;
    acquired.addEventListener("release", () => {
      if (sentinel === acquired) sentinel = null;
    });
    return { active: true, supported: true };
  } catch (error) {
    return { active: false, supported: true, error: String(error) };
  }
}

External links

Exercise

Test supported, unsupported, denied, hidden, visible-again, and explicit-exit paths.
Hint
Observe real hand movement and failure states.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.