Computer vision / 2026 / Live in the browser
Attention Detector
A desktop app that watches the webcam and, once you stop facing the screen, pulls Chrome to the front, launching it on Gmail if it is not open.
01
The problem
Two hard parts. Deciding someone has looked away needs head angle, not face presence, because a face turned 40 degrees is still a face. And Windows deliberately refuses to let a background process take focus, which is exactly what this app has to do.
02
How I approached it
MediaPipe Face Landmarker runs in the renderer on WASM with the GPU delegate and returns a 4x4 facial transform per frame. Yaw and pitch come out of its rotation block and are measured against a calibrated centre, since a webcam above the monitor reads every head as tilted. Blink blendshapes can count closed eyes as looking away. The main process calls user32 through koffi: it enumerates top-level windows, keeps the ones owned by chrome.exe, restores the most recent if minimised, and taps Alt before SetForegroundWindow to satisfy the foreground lock rule. Detection runs on setInterval with renderer backgrounding disabled, because requestAnimationFrame stops the moment Chrome covers the window.
03
The outcome
Head pose tracked about 12 times a second, and one switch per look-away that re-arms only when you face the screen again, so it never fights you for focus while you are gone. The desktop app and the browser build load the same page; without the preload bridge the switch is drawn on screen instead of performed.
Camera: this runs entirely in your browser. No video is uploaded or stored.