<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>24353</bug_id>
          
          <creation_ts>2014-01-22 08:16:14 +0000</creation_ts>
          <short_desc>Possible race between &lt;video&gt; loadstart and window.onload</short_desc>
          <delta_ts>2014-01-29 10:48:49 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#loading-the-media-resource</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>philipj</cc>
    
    <cc>zcorpan</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>98868</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2014-01-22 08:16:14 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/
Multipage: http://www.whatwg.org/C#loading-the-media-resource
Complete: http://www.whatwg.org/c#loading-the-media-resource
Referrer: 

Comment:
Possible race between &lt;video&gt; loadstart and window.onload

Posted from: 212.247.211.200 by simonp@opera.com
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36 OPR/19.0.1326.39 (Edition Next)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98870</commentid>
    <comment_count>1</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2014-01-22 08:34:26 +0000</bug_when>
    <thetext>Consider the following document

&lt;!doctype html&gt;
&lt;script&gt;
var v = document.createElement(&apos;video&apos;);
var s = document.createElement(&apos;source&apos;);
v.appendChild(s);
var events = [];
v.onloadstart = function(e) { events.push(e); }
onload = function(e) { events.push(e); }
&lt;/script&gt;
&lt;button onclick=&quot;alert(events)&quot;&gt;check&lt;/button&gt;

Interesting bits of RSA:

Step 3:
[[
Set the media element&apos;s delaying-the-load-event flag to true (this delays the load event).
]]

Step 8:
[[
⌛ Queue a task to fire a simple event named loadstart at the media element.
]]

This uses the media element event task source.

Step 9.20:
[[
⌛ Set the element&apos;s delaying-the-load-event flag to false. This stops delaying the load event.
]]

The End says at step 6:
[[
Spin the event loop until there is nothing that delays the load event in the Document.
]]

and step 7:
[[
Queue a task to run the following substeps:

...

If the Document is in a browsing context, create a trusted event named load ...
]]

This uses the DOM manipulation task source.

Now, it seems to me that it is possible that the video can reach step 9.20 before the loadstart task is run. The End can also be run before the loadstart task is run. In this case, nothing delays the load event, so The End doesn&apos;t spin the event loop. The End then queues the load event. Now we have two events on different task sources and it&apos;s not predictable which will fire first.

Possible fix is to queue a task using the DOM manipulation task source in RSA 9.20 to stop delaying the load event.

Same for RSA 9.6.6 for the src steps I think.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99372</commentid>
    <comment_count>2</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-01-28 23:50:20 +0000</bug_when>
    <thetext>Ok I don&apos;t know if this fixes all the cases, but it should fix the ones above, at least; let me know if you see anything wrong:</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99373</commentid>
    <comment_count>3</comment_count>
    <who name="">contributor</who>
    <bug_when>2014-01-28 23:50:29 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r8434.
Check-in comment: Try to reduce race conditions involving media elements and the &apos;load&apos; event.
http://html5.org/tools/web-apps-tracker?from=8433&amp;to=8434</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99396</commentid>
    <comment_count>4</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2014-01-29 10:48:49 +0000</bug_when>
    <thetext>LGTM</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>