I am novice javascript developer. I have a bookmarklet that can get the current time of a youtube video.
javascript:(function(){ ytplayer = document.getElementById("movie_player"); var secs = ytplayer.getCurrentTime(); alert(`${secs}`);})();It works fine on youtube.com. However, when I apply the same logic to an iframe-based website (url here). According to youtube API reference, I use function onYouTubePlayerAPIReady(). but nothing happens when I run the bookmarklet. Here is the code
javascript:function onYouTubePlayerAPIReady() { var ytplayer = new YT.Player('widget2'); var secs = ytplayer.getCurrentTime(); alert(`${secs}`);}Does any youtube API expert can spot the issue?
Here is the iframe of the sample youtube from the website
<iframe frameborder="0" allowfullscreen="1" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" title="YouTube video player" width="100%" height="100%" src="https://www.youtube.com/embed/eSWwIQzKsbY?autoplay=1&mute=0&controls=1&start=0&origin=https%3A%2F%2Fyou-tldr.com&playsinline=1&showinfo=0&rel=0&iv_load_policy=3&modestbranding=1&enablejsapi=1&widgetid=1" id="widget2" data-gtm-yt-inspected-1_25="true"></iframe>