Blog home

window.requestAnimationFrame troubles

Posted by in history

Some old posts about window.requestAnimationFrame (like this one) depend on the callback taking, as an argument, the time the next frame will be displayed. Unforunately, as some have noticed, they’re kind of wrong: it’s the time the frame started processing. Here’s what I gathered when I tried to figure out why…

The current state of affairs seems to be able to differ from what MDN and the spec say only in Webkit on Cocoa (OS X and iOS), but testing on an iPhone and a Macbook gives results in line with the spec.

By May 2011, it was noticed that the spec didn’t actually define the callback’s argument unambiguously.

In November, discussion arrived at the following consensus:

The working group feels the time parameter should be the time of the next frame. As developers will typically want to construct the next frame to be painted, this seems like the intuitive option. James or Cameron should also follow up with CSS animations and other animation specs and ensure this design is consistent with any similar concepts they may have.

In May, the relevant section of the spec was updated to match what the actual behavior had been all along in IE, Chrome, and Firefox.

(In March, plans to make the time parameter a DOMHighResTimestamp had moved forward, but this didn’t actually have any effect on the semantic meaning of the callback parameter.)

I have to wonder whether Paul Irish’s message approving local high-resolution timestamps was also intended to approve of this change, from “next frame display time” to “started processing”, given some seemingly-mostly-ignored comments from outside developers on the mailing list (1, 2).

The last word on the issue was that the predicted time of refresh would likely be passed as a second parameter. Alas, this could conflict with intentions to depend on element visibility; though this post of Paul Irish suggests that intention’s gone.

Side note: The MDN docs were only updated to the spec this January, even though info on DOMHighResTimestamp was there in August 2013 when the relevant change landed.

Newer: Sol geometry and the tangent bundle of a hyperbola Older: Highlights of Simon Tatham's puzzle collection