10

I want to set <track src to a "data:" URI.

<video>
    <source src="http://the.othersite/foo.mp4">
    <track src="data:text/vtt,WEBVTT">
</video>

However, I get

Cross-origin text track load denied by Cross-Origin Resource Sharing policy.

The error occurs in both Chrome and Safari.

If I set track src to "/foo.vtt", it works. The "Origin" of Data URI is not the current page uri?

Jsfiddle example here. (Look at the error output in the Console.)

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
colder
  • 644
  • 7
  • 12

1 Answers1

0

Browser support for setting the track data via data URIs appears to be incomplete and buggy. Here is a list of bug reports for each browser.

Firefox appears to support setting track directly in the HTML using base64 encoded data URIs (jsfiddle). Updating the track src via JavaScript appears to work but doesn't appear to affect that actual track data that is in use.

If you really need to update the track data via JavaScript, you can manually parse the WEBVTT text and add it a Cue at-a-time. This page describes all the methods that don't work for including VTT data directly in the page and gives an example of parsing and Cue loading at the end.

kanaka
  • 70,845
  • 23
  • 144
  • 140