Crossorigin errors when loading VTT file
See here for an update list of browser with native WebVTT support. If your browser does not support native CC as WebVTT you have to construct your own parser in JavaScript to display them (note there are other CC format like SRT and TTML/DFXP).
You can find reliable information about the track element here and here. Note that there is a difference between what is referred to as subtitles, captions and descriptions.
Most browsers won't support a track tag when used with an audio tag - though in theory they should - you will find practically it does not work as of today. Maybe it has something to do with WebVTT meaning Web Video Text Tracks. This is described here.
You have to build your own parser if you want to display your closed captions along an audio tag. I would suggest you take a look at the source of mediaelementjs to get an idea on how to tackle this.
CORS is only required when you are requesting CC files that are not on the same domain as the page hosting the audio/video tag. It should not be necessary in your case. More about CORS.
Your error message seems to indicate you have a misconfiguration somewhere in your system (maybe your vtt file is on NFS?).
This is an old post, but the first I hit when Googling for Text track from origin 'SITE_HOSTING_TEXT_TRACK' has been blocked from loading: Not at same origin as the document, and parent of track element does not have a 'crossorigin' attribute. Origin 'SITE_HOSTING_PAGE' is therefore not allowed access.
The OP seems to be having this issue locally and he could fix that by disabling Chrome's web security as shown above. But users will more often see this when accessing their text tracks from a different domain. To fix it in a production environment for all users, you need to do two things:
- Add the right CORS headers to the site hosting the VTT file.
- Add the
crossorigin="anonymous"
attribute to your site's audio/video element.
If you do not have access to the site hosting the video file, you might be stuck. But if you do, you should add the header Access-Control-Allow-Origin:'*'
. I'm handling it on a Node/Express server like this:
var app = express()
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
next()
})
The audio/video element is an easier fix. In your site's HTML page, add the following crossorigin attribute.
<audio controls crossorigin="anonymous">
<source src="myaudio.mp3" type="audio/mpeg">
<track kind="caption" src="my_file_hosted_on_a_different_domain.vtt" srclang="en" label="English">
</audio>
I hope this answer helps someone... it was an annoying issue to troubleshoot.