However, I am at a bit of a loss as to how to extract the ad video ID itself.
In the browser inspector, the only places I can find the ad video ID are:
Within the URL for ytp-cued-thumbnail-overlay-image
As adVideoId within var ytInitialPlayerResponse, which itself is within <script nonce="rwc3vYf3vRLEyNQKsJOgig">, where rwc3vYf3vRLEyNQKsJOgig changes with every video.
What would be the best way to extract the advertisement video ID?
Apologies for if I'm going about this the wrong way. I am (very!) new to JavaScript, but interested in learning. Please let me know if I've broken any community rules, or committed any other sort of faux pas. Thanks! :)
What’s the challenge with extracting from the url?
One problem with the first approach is that ytp-cued-thumbnail-overlay-image does not seem to exist in all cases, so it seems (to me, at least) like an unreliable method.
For the second approach, I'm not sure how one would go about locating the adVideoId text.
Should I be trying to automatically search the page HTML for it?
Should I be trying to figure out where it is ahead of time, and navigate to it via the DOM tree?