Created
September 20, 2018 20:31
-
-
Save olegp/a32dcf2c07603b2aafcb6e462c044f10 to your computer and use it in GitHub Desktop.
Active tab change detection in Chrome Extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let activeTabId, lastUrl, lastTitle; | |
function getTabInfo(tabId) { | |
chrome.tabs.get(tabId, function(tab) { | |
if(lastUrl != tab.url || lastTitle != tab.title) | |
console.log(lastUrl = tab.url, lastTitle = tab.title); | |
}); | |
} | |
chrome.tabs.onActivated.addListener(function(activeInfo) { | |
getTabInfo(activeTabId = activeInfo.tabId); | |
}); | |
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { | |
if(activeTabId == tabId) { | |
getTabInfo(tabId); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment