Reputation: 21
i am creating a youtube chrome extension and try to load extension from background page automatically when any youtube video or channel page open but extension will not load untill i refresh same page again. i am using chrome.tabs.onUpdated.addListener to fire my script. i am already given tab permission on menifest.json file here is my background.js file is as
function checkForValidUrl(tabId, change, tab) {
if (change.status == 'loading' && change) {
//check for url is valid or not...and then load html through javascript
} }
chrome.tabs.onUpdated.addListener(checkForValidUrl);
thanks in advance.......
Upvotes: 2
Views: 840
Reputation: 1268
Detecting hash changes should work: WindowEventHandlers.onhashchange
I use it for checking to see if an email was opened in Gmail. Gmail also changes the URL similar to how Youtube does.
Example using your function name:
window.addEventListener("hashchange", checkForValidUrl, true);
Upvotes: 0