Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
Chrome Extension properly gets current URL and title, except on Youtube

I made this extension as an exercise in passing current page parameters onto another script later down the road. Using chrome.tabs.getSelected, I can retrieve the url and title of almost any page that I navigate to...except Youtube. For some reason, the alert box shows the current URL, but the previous title.

I have tried delaying the retrieval of the title, but that has produced other problems like multiple alerts or "undefined" values.

background.js

chrome.webNavigation.onHistoryStateUpdated.addListener(function(details) {
    chrome.tabs.getSelected(null,function(tab) { // null defaults to current window
        if(typeof chrome._LAST_RUN === 'undefined' || notRunWithinTheLastSecond(details.timeStamp)){
            // Fires only when details.url === currentTab.url
            chrome._LAST_RUN = details.timeStamp;
                    var myurl = tab.url;
                    var mytitle = tab.title;
                    zurl = myurl + "\r\n" + "\r\n" + mytitle;
                    alert(zurl);
        }
    });
});
const notRunWithinTheLastSecond = (dt) => {
    const diff = dt - chrome._LAST_RUN
    if (diff < 2000){
      return false
    } else {
      return true
    }
  }

manifest.json

"permissions"       : [ 
    "tabs",
    "webNavigation"
]
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!