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"
]