youtube movie-player returning undefined on methods getDuration() etc, unless invoked in browser

66 views Asked by At

If I open youtube, navigate to a video and run the following in the browser console, it works flawlessly.

const video = document.getElementById("movie_player") 
video.getDuration()

If I'm making a chrome extension where the content script injects a button on the page at the document's end, and pressing the button executes the above code; it will give me undefined.

I'm not making my own iframe, I'm working with what's already on youtube. And it doesn't seem to matter how long I wait for before I press the button, it will always give me undefined.

Are we supposed to use the youtube API v3 to deal with this? because I was under the impression that it was designed to be used for when you want to tinker with your own iframes.

0

There are 0 answers