I'm building a chrome extension that injects a content script into YouTube pages to scrape its entire HTML. I don't need it parsed within the extension, but what's most important in the scraped HTML is the recommendation list. I understand that YouTube is a Single Page Application so it loads dynamically, and I've tried getting the HTML listening to all kinds of events (transitionend, yt-navigate-finish (problem: this event fires 3 times), yt-page-data-updated) but the recommendation list is never included in the scraped HTML. For example, this code from the solution mentioned above doesn't work:
my content.js
(document.body || document.documentElement).addEventListener('transitionend', function(event){
if (event.target.id === 'progress' && event.propertyName === 'width') {
// it's also not always the case that a transitionend event on 'progress' with propertyName 'width' exists
var x = document.body.outerHTML;
chrome.runtime.sendMessage({
url: location.href,
source: x,
// source:document.getElementsByTagName("ytd-compact-video-renderer"),
message: 'readHTML'
});
}
});
I'm wondering which event I should listen for in order to get the recommendation list. I've tried monitorEvents() on the elements that host the list ('secondary','secondary-inner','items', etc.) but I couldn't find any events which signal that the list has been loaded fully. Any help is appreciated. Thanks!