soufiane yakoubi
soufiane yakoubi

Reputation: 951

wrong time passed to callback called by requestAnimationFrame

I'm using a simple requestAnimationFrame loop which starts immediately after the DOM is created. I needed to use the time argument which is passed to the callback, but I noticed that in the first few frames the time is wrong. Here's what happens when I run this code on firefox :

function loop(time) {

    console.log(time);

    // do something with time to animate the canvas 

    requestAnimationFrame(loop);
}

requestAnimationFrame(loop);

console

I can skip those 3 first frames with a simple condition, but why does it behave that way?

Upvotes: 1

Views: 82

Answers (1)

Kaiido
Kaiido

Reputation: 137171

This is a Firefox bug, caused by the fact they clear the console in the will-navigate state instead of doing it in navigated.

So indeed, you may get logs that did happen in between these two states persist on the next session, but that's just in the console, your code won't see these.

Upvotes: 1

Related Questions