In my background.js I am listening for a page reload using tabs.onUpdated
, and executing a script reload.js
after the changeInfo.status == 'complete'
. But if there is some server-side rendering, for example, next.js website, after we navigate to a new link inside that website, the reload.js stays at the page, instead of deleting and updating, the changes keep on adding.
How can I execute the reload.js script only if there is a whole web page reload instead of server side load?
background.js
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
chrome.scripting.executeScript({
target: { tabId: tabId },
files: ['reloaded.js'],
}, () => {
console.log('works fine')
});
}
});