You can detect failures in the JS timeline (for example, a sleep laptop, warning windows that block JS excecution, statements debuggerthat open the debugger) by comparing the time changes on the wall to the expected timer delay. For example:
var SAMPLE_RATE = 3000;
var lastSample = Date.now();
function sample() {
if (Date.now() - lastSample >= SAMPLE_RATE * 2) {
}
lastSample = Date.now();
setTimeout(sample, SAMPLE_RATE);
}
sample();
source
share