Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Last active March 3, 2026 11:08
Show Gist options
  • Select an option

  • Save gkucmierz/fc357ce424bf809a3d378a3a32d83cd4 to your computer and use it in GitHub Desktop.

Select an option

Save gkucmierz/fc357ce424bf809a3d378a3a32d83cd4 to your computer and use it in GitHub Desktop.
const lagDetector = (() => {
let run = true;
const TRESHOLD = 1e3/60 + 1; // ~60 FPS
let lastTime = +new Date();
(function loop() {
const time = +new Date();
const diff = time - lastTime;
if (diff > TRESHOLD) {
console.log(`Interface blocked for ${diff}ms`);
}
lastTime = time;
run && setTimeout(loop, 1);
})();
return { stop: () => run = false };
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment