javascript: Why does my value increase by one ton when the tab changes from inactive to active?


Basically, I have a lerp function similar to this: client interpolation for a 100% game on the server when a new server update is received, the update frequency is added to a variable (msAhead) and the delta is subtracted from each Customer's framework But when I do, the variable msAhead increases a lot when the tab changes from inactive to active. Here is my code:

msAhead + = updateFrequency; // when a new update is received.

(function loop (now) {

var now = Date.now ();
delta = now - Time;

Time = now;

msAhead - = delta;

console.log (msAhead);

requestAnimationFrame (loop)

}) (0);

How can I solve my problem?