Most browser timers are way heavier than they need to be—wrapped in ad scripts, cookie banners, and frameworks just to count down five minutes. When I need a clean timer for rehearsal pacing, sprint blocks, or quick work intervals, I want something dark-mode, keyboard-first, and completely offline-capable.
So I put together Cue Timer in a single index.html page with zero dependencies and zero external audio assets.
1. Avoiding setInterval Drift
The classic trap with JavaScript timers is decrementing a counter inside setInterval(..., 1000). Browser tabs throttle background intervals, so a 15-minute timer can easily drift by several seconds.
Instead of counting ticks, the timer records a target timestamp using performance.now() when you hit Start, and calculates the delta on every requestAnimationFrame:
function tick() {
remainingMs = endTime - performance.now();
if (remainingMs <= 0) {
// trigger completion & chime
return;
}
render(remainingMs);
rafId = requestAnimationFrame(tick);
}
Even if the tab gets backgrounded, the moment you glance back (or the clock crosses zero), the readout stays dead accurate.
2. Procedural Chimes with the Web Audio API
Shipping an .mp3 or .wav asset for a single alert ping breaks the portable single-page setup. Using the browser's built-in AudioContext, you can synthesize a clean two-tone sine chime in about 15 lines of code:
function playChime() {
const AudioContextClass = window.AudioContext || window.webkitAudioContext;
if (!audioCtx) audioCtx = new AudioContextClass();
if (audioCtx.state === 'suspended') audioCtx.resume();
const now = audioCtx.currentTime;
[523.25, 659.25].forEach((freq, i) => {
const osc = audioCtx.createOscillator();
const gain = audioCtx.createGain();
osc.type = 'sine';
osc.frequency.setValueAtTime(freq, now + i * 0.14);
gain.gain.setValueAtTime(0.001, now + i * 0.14);
gain.gain.exponentialRampToValueAtTime(0.18, now + i * 0.14 + 0.02);
gain.gain.exponentialRampToValueAtTime(0.0001, now + i * 0.14 + 0.55);
osc.connect(gain);
gain.connect(audioCtx.destination);
osc.start(now + i * 0.14);
osc.stop(now + i * 0.14 + 0.6);
});
}
The quick exponential attack and release prevents the harsh digital "click" you get when cutting an oscillator off abruptly.
3. Keyboard-First Controls
If you're using a timer while working or calling cues, reaching for a mouse defeats the point. Everything maps to single keys:
-
Space— Start / Pause -
R— Reset current preset -
1/2/3— Jump straight to 5, 15, or 25 minutes
The full source is up on my GitHub at github.com/donovanlafferty/cue-timer.
I'm Donovan Lafferty, an Orlando-based developer and entertainment operations specialist. You can find more of my small web utilities on GitHub, audio experiments on SoundCloud, and project demos on YouTube.
Top comments (1)
The performance.now() plus requestAnimationFrame choice is the part I would steal — counting setInterval ticks is how a 15-minute timer quietly drifts by seconds in a backgrounded tab, and anchoring to an end timestamp is the fix that actually holds. The procedural chime is the second smart cut: fifteen lines of Web Audio instead of shipping an .mp3 keeps the whole thing a single portable file. The edge I keep coming back to is the moment the cue actually fires — requestAnimationFrame stops in a backgrounded tab, so if the clock crosses zero while the tab is hidden, does the chime wait until you glance back, or do you have a setTimeout poller as a backup? And how does the AudioContext behave if the tab has been backgrounded long enough that the browser suspends it — does the chime still sound on return, or is that cue lost?