wait for tabs to load when reinjecting (#849)
This commit is contained in:
parent
02a575a9d6
commit
7109d33e4e
|
@ -54,15 +54,29 @@ const contentScripts = (() => {
|
||||||
|
|
||||||
function injectToAllTabs() {
|
function injectToAllTabs() {
|
||||||
return queryTabs({}).then(tabs => {
|
return queryTabs({}).then(tabs => {
|
||||||
|
const busyTabs = new Set();
|
||||||
for (const tab of tabs) {
|
for (const tab of tabs) {
|
||||||
// skip lazy-loaded aka unloaded tabs that seem to start loading on message in FF
|
// skip unloaded/discarded tabs
|
||||||
if (tab.width) {
|
if (!tab.width || tab.discarded) continue;
|
||||||
|
// our content scripts may still be pending injection at browser start so it's too early to ping them
|
||||||
|
if (tab.status === 'loading') {
|
||||||
|
busyTabs.add(tab.id);
|
||||||
|
} else {
|
||||||
injectToTab({
|
injectToTab({
|
||||||
url: tab.url,
|
url: tab.url,
|
||||||
tabId: tab.id
|
tabId: tab.id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (busyTabs.size) {
|
||||||
|
chrome.tabs.onUpdated.addListener(function _(tabId, {status}, {url}) {
|
||||||
|
if (status === 'complete' && busyTabs.has(tabId)) {
|
||||||
|
busyTabs.delete(tabId);
|
||||||
|
if (!busyTabs.size) chrome.tabs.onUpdated.removeListener(_);
|
||||||
|
injectToTab({tabId, url});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user