Assumptions: rAF now
time is calculated at the time the set of callbacks are all triggered. Therefore any blocking that happens before the first callback of th
The timestamp passed in to the requestAnimationFrame()
callback is the time of the beginning of the animation frame. Multiple callbacks being invoked during the same frame all receive the same timestamp. Thus, it would be really weird if performance.now()
returned a time before the parameter value, but not really weird for it to be after that.
Here's the relevant specification:
When the user agent is to run the animation frame callbacks for a Document document with a timestamp now, it must run the following steps:
If the value returned by the document object’s hidden attribute is true, abort these steps. [PAGE-VISIBILITY]
Let callbacks be a list of the entries in document’s list of animation frame callbacks, in the order in which they were added to the list.
Set document’s list of animation frame callbacks to the empty list.
For each entry in callbacks, in order: invoke the Web IDL callback function, passing now as the only argument, and if an exception is thrown, report the exception.
So you've registered a callback (let's say just one) for the next animation frame. Tick tick tick, BOOM, time for that animation frame to happen:
performance.now()
and compares it to the now value passed in as a parameter.Because a brief but non-ignorable amount of time may pass between step 1 and step 6, the return value from performance.now()
may indicate that a couple of microseconds, or even more than a couple, have elapsed. That is perfectly normal behavior.