{"success":true,"name":"background-tabs-throttle-timers-compute-elapsed-time-from-ti","description":"A countdown, clock, or scheduler drifts when the tab or app is in the background","category":"ai-brimind","path":"ai-brimind/background-tabs-throttle-timers-compute-elapsed-time-from-ti/SKILL.md","file":"SKILL.md","content":"---\nname: background-tabs-throttle-timers-compute-elapsed-time-from-ti\ndescription: \"A countdown, clock, or scheduler drifts when the tab or app is in the background\"\n---\n\n# Background Tabs Throttle Timers: Compute Elapsed Time From Timestamps, Not Tick Counts\n\n## When to use\nCode accumulates time by counting timer ticks (interval fires × step), and accuracy matters even when the page is backgrounded or the device sleeps.\n\n## Example request\na 10-minute countdown shows 6 minutes left after the tab was hidden → background tabs fire timers rarely; missing ticks. a clock built by adding one second per tick → drifts within minutes even foregrounded; accumulated slippage. a session timeout counted by intervals → sleep pauses the counting, the session never expires; suspended ticks. — each trusted ticks to measure time.\n\n## Instructions\nAct as a sailor who navigates by the stars, not by counting oar strokes: timer ticks tell you the code ran, never how much time passed. Browsers and devices throttle timers aggressively in background tabs and during sleep — intervals fire once a minute or not at all — so any duration built by accumulating ticks silently loses the hidden time. Invert the design: record the reference timestamp (start time, deadline) once, and on every tick or wake-up, compute the truth from the current time versus that reference — the display updates via timers, but the value comes from arithmetic on timestamps, so a tab hidden for an hour shows the correct state the instant it returns. Also refresh on the visibility-change event, so returning users see truth immediately rather than after the next lazy tick. Choose the right clock: the monotonic performance clock for measuring durations (immune to the user changing their system clock), wall-clock time for real-world deadlines. And never trust the client's clock for anything that matters — expiries and deadlines are verified by the server. Only proceed once no correctness depends on a timer having actually fired.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #752\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}