Ten Seconds to Next Episode — JavaScript Bug Hunt

Inspired by every streaming service's autoplay countdown. The "Next episode in N…" overlay is skipping straight from 2 to launch, and sometimes fires the…

  • Language: JavaScript
  • Layer: Frontend
  • Difficulty: Easy
  • Concepts: Timers, Off-by-one
  • Modelled on: Netflix autoplay
  • Visible tests: shows the full window at the start; shows 1 for the final second; never launches early
  • Reward: 50 XP for a complete fix

Briefing

Inspired by every streaming service's autoplay countdown. The "Next episode in N…" overlay is skipping straight from 2 to launch, and sometimes fires the next episode a full second early.

Both symptoms come from the same two lines in countdown.js.

Bug report

BUG-9001 · Reported by: playback UX

Spec (10s window):

  • secondsLeft(startMs, nowMs) shows the CEILING of the remaining time: at 9.2s remaining it must show 10, at 0.5s it shows 1, at 0 exactly it shows 0.
  • shouldLaunch(startMs, nowMs) is true only once the full window has elapsed.

Observed: the overlay shows 9 immediately, and launch fires at 9.1s.

Logs

[autoplay] t+0.0s label=9 (expected 10)
[autoplay] launched at t+9.1s (expected t+10.0s)

The code as shipped

src/player/countdown.js (editable)

// Autoplay countdown for the next-episode overlay.
var WINDOW_MS = 10000;

exports.secondsLeft = function (startMs, nowMs) {
  var remaining = WINDOW_MS - (nowMs - startMs);
  if (remaining <= 0) return 0;
  return Math.floor(remaining / 1000);
};

exports.shouldLaunch = function (startMs, nowMs) {
  return nowMs - startMs > WINDOW_MS - 1000;
};

Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.