[whatwg] <video> ... <script> race condition

Philip Jägenstedt philipj at opera.com
Fri May 13 02:40:59 PDT 2011


Problem:

<video src="video.webm"></video>
...
<script>
document.querySelector('video').oncanplay = function() {
   /* will it run? */
};
</script>

In the above the canplay event can be replaced with many others, like  
loadedmetadata and loadeddata. Whether or not the event handler has been  
registered by the time the event is fired depends on how fast decoding is,  
how fast the network is and how much "..." there is.

This is not new information, Simon Pieters wrote extensively about the  
problem in  
http://dev.opera.com/articles/view/consistent-event-firing-with-html5-video/

The reason I write now is that in one of our projects this exact race  
condition happens to be hit for http://html5demos.com/video which is where  
the above code snippet comes from.

Does anyone have ideas about how to deal with this problem, which *is*  
going to appear on many real-world pages? Is there any browser that has  
already done something to mitigate the problem?

-- 
Philip Jägenstedt
Core Developer
Opera Software


More information about the whatwg mailing list