Chrome.tabs.onUpdated.addListener (), called multiple times

I am doing a chrome extension, and my problem is that chrome.tabs.onUpdated.addListener () is called multiple times.

My code is like this

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { if(changeInfo.status == 'complete' && tab.status == 'complete' && tab.url != undefined){ doSomething } }); 

This is due to Chrome Issue 162543, and it looks to be fixed, but I still have this problem.

+5
source share
1 answer

Remember that chrome.tabs.onUpdated will also be run for iframes, if the page contains many frames, each completed iframe raises an event, although you noted changeInfo.status .

To solve this problem, you can see my answer in this post on the Chrome extension - refresh the page twice and then delete it on YouTube , and use chrome.webNavigation.onCompleted or chrome.webNavigation.onHistoryStateUpdated , which depends on your testing sites.

+2
source

Source: https://habr.com/ru/post/1210113/


All Articles