Skip to content

Instantly share code, notes, and snippets.

@mrv1k
Last active October 19, 2022 22:09
Show Gist options
  • Save mrv1k/b7234ea466e8751bfe52ae5bce0396b5 to your computer and use it in GitHub Desktop.
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
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