A tiny, dependency-free way to know whether your user is looking at the page โ and whether they're still there.
This whole page is wired to one ifvisible instance. Try it:
switch tabs, minimize, or just
stop touching your mouse/keyboard and watch.
This 1s interval auto-pauses when you go idle or hide the tab, and resumes when you're back โ no ticks are wasted.
Listening to focus, blur,
idle, wakeup,
statusChanged, and the Page Lifecycle
freeze / resume events.
import ifvisible from "ifvisible.js"; // React to attention ifvisible.on("blur", () => video.pause()); ifvisible.on("focus", () => video.play()); // React to inactivity (default 30s) ifvisible.setIdleDuration(30); ifvisible.on("idle", () => stream.pause()); ifvisible.on("wakeup", () => stream.resume()); // Intervals that pause themselves when nobody's watching ifvisible.onEvery(1, () => poll());