javascript - Adding a listener that fires whenever the user changes tab -
i'm creating chrome extension , trying function fire everytime user changes tab. i've been looking @ listeners in webrequest api, , chrome.tabs couldn't figure use, , not use.
the information need tab url.
take @ chrome.tabs.onactivated:
fires when active tab in window changes. note tab's url may not set @ time event fired, can listen onupdated events notified when url set.
— google documentation
chrome.tabs.onactivated.addlistener(function(activeinfo) { chrome.tabs.get(activeinfo.tabid, function (tab) { mysupercallback(tab.url); }); }); chrome.tabs.onupdated.addlistener(function(tabid, changeinfo, updatedtab) { chrome.tabs.query({'active': true}, function (activetabs) { var activetab = activetabs[0]; if (activetab == updatedtab) { mysupercallback(activetab.url); } }); }); function mysupercallback(newurl) { // ... }
it works in background pages (as locercus confirmed in a comment), please consider using event pages (stable since chrome 22) instead.
Comments
Post a Comment