This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 11981 - <video> There's a race condition with autoplay if the autoplay attribute is removed in e.g. 'loadstart' event listener
Summary: <video> There's a race condition with autoplay if the autoplay attribute is r...
Status: RESOLVED WONTFIX
Alias: None
Product: HTML WG
Classification: Unclassified
Component: LC1 HTML5 spec (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: HTML WG Bugzilla archive list
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-04 15:20 UTC by contributor
Modified: 2011-08-04 05:01 UTC (History)
8 users (show)

See Also:


Attachments

Description contributor 2011-02-04 15:20:24 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/complete/video.html
Section: http://www.whatwg.org/specs/web-apps/current-work/#handling-first-frame-available

Comment:
There's a race condition with autoplay if the autoplay attribute is removed in
e.g. 'loadstart' event listener

Posted from: 85.227.154.141 by simonp@opera.com
Comment 1 Simon Pieters 2011-02-04 15:27:17 UTC
The resource selection algorithm queues a task to fire 'loadstart' (and subsequent events are also queued). However, readyState transitions are immediate and take effect immediately. So if a video is cached or is loaded locally, you could get to HAVE_ENOUGH_DATA before 'loadstart' is fired, which means that the video is autoplayed before a script has had a chance to remove the autoplay attribute.

To fix this I suggest that the readyState transition to HAVE_ENOUGH_DATA should say something like:

If the autoplaying flag is true, and the paused attribute is true, then queue a task to run the following steps:
1. If the media element has an autoplay attribute specified, and the media element's Document's browsing context did not have the sandboxed automatic features browsing context flag set when the Document was created, then the user agent may also set the paused attribute to false, fire a simple event named play, and fire a simple event named playing.

(I have not pondered about what effect this has on the sandboxed automatic features stuff.)
Comment 2 Ian 'Hixie' Hickson 2011-02-09 01:06:13 UTC
If you don't want it to autoplay, why would you set autoplay? I don't understand the use case for worrying about this.
Comment 3 Philip Jägenstedt 2011-03-08 17:03:13 UTC
(In reply to comment #2)
> If you don't want it to autoplay, why would you set autoplay? I don't
> understand the use case for worrying about this.

This problem was found when someone was trying to develop an extension to stop media elements from autoplaying.
Comment 4 Philip Jägenstedt 2011-04-06 12:00:13 UTC
Another example of event raciness that I just stumbled upon:

We had a test for checking the order of events in for preload=metadata. In the loadstart event handler, event handler for 'progress', 'suspend', 'abort', 'error', 'loadedmetadata', 'loadeddata', 'canplay', and 'canplaythrough' were registered, but it depends on chance which of these have already been fired. In our case, we missed the first progress event, but got the rest.

Of course it's possible to write code to avoid the race conditions, but if we as browser developers accidentally do things like this, then we can be 100% sure that web authors will also inadvertently come to depend on the most common outcome of race conditions in common browsers.
Comment 5 Ian 'Hixie' Hickson 2011-06-02 23:45:03 UTC
> This problem was found when someone was trying to develop an extension to stop
> media elements from autoplaying.

That's something that should be done natively by the UA.

If an extension is actually going to do this, it should be done from mutation events (or their brethren), long before 'loadstart' fires.

We can't do what comment 1 suggests since that would block autoplay behaviour if there was another task running (e.g. with an alert()).

Comment 4 seems to be a separate issue. That issue is present across the Web platform, it's not unique to <video>. We can't gate the processing of video on whether JS has handled the previous step, that would just kill performance in any case where there was a high load.


EDITOR'S RESPONSE: This is an Editor's Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Rejected
Change Description: no spec change
Rationale: see aboe
Comment 6 Philip Jägenstedt 2011-06-09 12:45:45 UTC
This and what I mentioned in comment 4 would be fixed by http://www.w3.org/Bugs/Public/show_bug.cgi?id=12267 so let's take the discussion there.
Comment 7 Michael[tm] Smith 2011-08-04 05:01:59 UTC
mass-moved component to LC1