跪拜 Guibai
← All articles
Frontend · JavaScript · Open Source

A Browser Extension That Knows When You Actually Left Your Desk

By JacksonChen ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Standing-desk reminders are a commodity, but most are oblivious to whether you actually moved. Tying reminders to OS idle state and lock-screen events — and handling the resulting state-machine complexity — turns a nag into a credible health log. For anyone stuck in Chrome all day, it's a zero-friction install that doesn't touch a server.

Summary

Most sedentary reminders are just countdown timers that pop up on schedule, regardless of whether you already stood up. This extension fuses Chrome's idle API and lock-screen signals to detect genuine breaks: a bathroom trip, a water refill, or a meeting all reset the clock automatically. It also handles edge cases that break naive timers — overnight shutdowns, Service Worker suspensions, and deadline crunches — through a 1,100-line finite state machine running entirely offline under Manifest V3.

A weighted health score (60 points for rest frequency, 40-point linear penalty for the longest single sit) gives immediate feedback when you overstay by even one minute. A "Busy Now" mode suppresses popups but keeps accumulating overtime in a red badge, so the warning stays visible without interrupting flow. Daily snapshots, a 7-day trend chart, and full JSON export/import make the data portable across machines.

Built with zero dependencies, zero build steps, and zero servers, the extension stores everything in chrome.storage.local. The developer started it after a hospital visit diagnosed cervical spine straightening and lumbar strain — the tool is now in daily use and planned for open-source release.

Takeaways
System idle and lock-screen events serve as dual signals for detecting real breaks; either trigger resets the sitting countdown.
A 60/40 weighted health score rewards rest frequency more heavily than it penalizes overtime, with a linear deduction that responds to even one minute of over-sitting.
"Busy Now" mode suppresses popups but keeps the timer running and shows a red overtime badge, so the warning persists without interruption.
Wake-up correction prevents absurd readings like "sat for 840 minutes" after an overnight shutdown by resetting timestamps when gaps exceed two work cycles.
Hot configuration updates preserve accumulated sitting time when the work interval changes, avoiding progress loss.
All data lives in chrome.storage.local; the extension is fully offline with no backend, no analytics, and no third-party SDKs.
Daily health snapshots, a 7-day trend chart, and JSON export/import make the log portable and reviewable across devices.
The Service Worker grew into a 1,100-line finite state machine handling states like WORKING, IDLE, RESTING, and PAUSED, with race-condition guards against duplicate popups.
Conclusions

Most "stand up" reminders fail not because people ignore them, but because the timer has no model of whether the user already stood up — idle detection closes that gap.

A linear penalty in the health score (rather than a stepped or threshold-based one) makes the cost of over-sitting immediately visible, which is a deliberate design choice favoring continuous feedback over delayed punishment.

Building this as a browser extension rather than a standalone app sidesteps corporate IT approval friction and smartwatch dependency — the lowest-friction distribution channel for desk workers is the browser they never close.

The project's origin story (a hospital diagnosis) explains why the feature set prioritizes non-intrusiveness: the reminder is a dialogue with options to defer, dismiss, or mark a false alarm, not a binary alarm clock.

Concepts & terms
Chrome idle API
A Chrome extension API that reports the system's idle state (active, idle, locked). It lets extensions detect when a user has stepped away from the machine without requiring polling or CPU wake locks.
Manifest V3 Service Worker
Chrome's latest extension architecture, where background scripts run as ephemeral Service Workers that can be suspended at any time. This forces developers to use alarms and state persistence instead of long-running timers like setInterval.
Finite state machine (in this extension)
The core logic models sitting behavior as discrete states — WORKING, IDLE, RESTING, PAUSED — with defined transitions. Each transition updates the timer, rest count, badge, and storage atomically to avoid inconsistent UI.
Linear overtime penalty
A scoring approach where each minute of over-sitting deducts a proportional, fixed amount from the health score (roughly 1 point per minute), rather than using thresholds or exponential curves. This makes small overages immediately visible.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗