Last active
October 19, 2022 22:09
-
-
Save mrv1k/b7234ea466e8751bfe52ae5bce0396b5 to your computer and use it in GitHub Desktop.
Filter out page refresh, page loaded or chrome pages from chrome.tabs.onUpdated
This file contains 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
const loadedTabs = {}; // global | |
// call within a function that hsa access to 'tab' permission | |
function load(tabId) { | |
[loadedTabs[tabId]] = response; | |
} | |
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { | |
if ((tabId !== tab.id && loadedTabs[tabId]) || /(chrome)(?:[/:-])/.test(tab.url)) return; | |
if (changeInfo.status === 'complete' && tab.active) { | |
doYourThing(); | |
} | |
}); | |
// if (this is not the same page AND already loaded) OR (chrome browser utility page) - like "chrome://" | |
// exit | |
// if passed | |
// proceed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment