I came across this problem, so maybe this is useful to someone. What suited me was listening to the yt-page-data-updated
event, which detects a video switch.
I was able to verify this with monitorEvents(document.body)
Chrome DevTools monitorEvents(document.body)
and getEventListeners(document.body)
when refreshing the page. But keep in mind that it will not work when the page is completely reloaded (by directly accessing the URL), so I had to coordinate with the load
event something like this:
window.addEventListener('load', function () { console.log('load'); }); window.addEventListener('yt-page-data-updated', function () { console.log('url change'); });
source share