Looking at the documentation for HTMLMediaElement.textTracks, it looks like subtitle/caption tracks should be nested under <video>
elements. This allows you to call .textTracks
on a video reference to get access to subtitles/captions.
I’ve found a number of smaller sites where this works and is setup as expected (ie: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track). However, on bigger sites like Netflix and Youtube, this doesn’t appear to work. In fact, their video elements typically have no children at all from what I can see.
This returns an empty list for a call like document.querySelector("video").textTracks
:
Is there not a standard way of handling subtitles/captions? Can someone explain why big sites do this differently from the documentation above, and if there’s another easy way to access their subtitles/captions? I’d like to build a browser extension that reacts based off of the captions in a video.