-
-
Save grim-reapper/ca68629efb578f5203518e7cfbf97411 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