Home > Net >  How to get the new youtube title when yt-navigate-finish runs?
How to get the new youtube title when yt-navigate-finish runs?

Time:11-19

I have this code:

function run() {
  browser.runtime.sendMessage({
    action: "notify",
    payload: {
      url: window.location.href,
      title: document.title,
    },
  });
}
window.addEventListener("yt-navigate-finish", run, true);

The url is correct, when I click on a new youtube video, the url changes. But the title is from the old video.

For example, I got this result:

{ url: "https://www.youtube.com/watch?v=UwMlgKUQaQ4", 
title: "Spire Labs: Fault-tolerance with Kubernetes on AWS - YouTubetest" 
}

The URL is different, the title s different (the title is from the video I was on previously.

CodePudding user response:

Read it from document.querySelector('a.ytp-title-link').textContent

  • Related