Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On a YouTube video page, how do I check if the video is currently playing an ad or the actual video via javascript?

I'm writing a chrome extension that displays content synced with the video.

I need to wait until the viewer finishes the ad/midroll before displaying the content. How do I do something such as the following via javascript?

if (videoOnAd == true) {
//do something
} else {
//do something else
}

Thanks in advance!

  • Kyler
like image 729
Kyler Chin Avatar asked Sep 16 '25 20:09

Kyler Chin


1 Answers

Solution!

if (document.querySelector("div.ad-showing")) {
           //Ad is active as a video 
           console.log("this is an ad")
        }
        else {
console.log("the video is playing")
}
}

Enjoy everyone!

like image 109
Kyler Chin Avatar answered Sep 18 '25 16:09

Kyler Chin