Take a look at chrome.tabs.onActivated:
Fires when the active tab in a window changes. Note that the tab's URL
may not be set at the time this event fired, but you can listen to
onUpdated events to be notified when a URL is 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 definitely works in background pages (as Locercus confirmed in a comment), but please consider using event pages (stable since Chrome 22) instead.