Search code examples
javascriptdomgoogle-chrome-extensionyoutubebrowser-extension

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

Solution

  • 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!