Lazify notifyAllTabs() and injectCS()
* notifyAllTabs: the active tab gets notified immediately, the rest lazily * notifyAllTabs + injectCS: don't notify lazy-loaded tabs in FF
This commit is contained in:
parent
c5a340e44e
commit
b4e00cd892
|
@ -202,9 +202,13 @@ contextMenus = Object.assign({
|
||||||
};
|
};
|
||||||
|
|
||||||
chrome.tabs.query({}, tabs =>
|
chrome.tabs.query({}, tabs =>
|
||||||
tabs.forEach(tab =>
|
tabs.forEach(tab => {
|
||||||
|
// skip lazy-loaded aka unloaded tabs that seem to start loading on message in FF
|
||||||
|
if (!FIREFOX || tab.width) {
|
||||||
contentScripts.forEach(cs =>
|
contentScripts.forEach(cs =>
|
||||||
pingCS(cs, tab))));
|
setTimeout(pingCS, 0, cs, tab));
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
20
messaging.js
20
messaging.js
|
@ -62,18 +62,30 @@ function notifyAllTabs(msg) {
|
||||||
const affectsPopup = affectsAll || msg.affects.popup;
|
const affectsPopup = affectsAll || msg.affects.popup;
|
||||||
const affectsSelf = affectsPopup || msg.prefs;
|
const affectsSelf = affectsPopup || msg.prefs;
|
||||||
if (affectsTabs || affectsIcon) {
|
if (affectsTabs || affectsIcon) {
|
||||||
// list all tabs including chrome-extension:// which can be ours
|
const notifyTab = tab => {
|
||||||
chrome.tabs.query(affectsOwnOriginOnly ? {url: URLS.ownOrigin + '*'} : {}, tabs => {
|
|
||||||
for (const tab of tabs) {
|
|
||||||
// own pages will be notified via runtime.sendMessage later
|
// own pages will be notified via runtime.sendMessage later
|
||||||
if ((affectsTabs || URLS.optionsUI.includes(tab.url))
|
if ((affectsTabs || URLS.optionsUI.includes(tab.url))
|
||||||
&& !(affectsSelf && tab.url.startsWith(URLS.ownOrigin))) {
|
&& !(affectsSelf && tab.url.startsWith(URLS.ownOrigin))
|
||||||
|
// skip lazy-loaded aka unloaded tabs that seem to start loading on message in FF
|
||||||
|
&& (!FIREFOX || tab.width)) {
|
||||||
chrome.tabs.sendMessage(tab.id, msg);
|
chrome.tabs.sendMessage(tab.id, msg);
|
||||||
}
|
}
|
||||||
if (affectsIcon && BG) {
|
if (affectsIcon && BG) {
|
||||||
BG.updateIcon(tab);
|
BG.updateIcon(tab);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
// list all tabs including chrome-extension:// which can be ours
|
||||||
|
chrome.tabs.query(affectsOwnOriginOnly ? {url: URLS.ownOrigin + '*'} : {}, tabs => {
|
||||||
|
getActiveTab().then(activeTab => {
|
||||||
|
const activeTabId = activeTab && activeTab.id;
|
||||||
|
for (const tab of tabs) {
|
||||||
|
if (tab.id === activeTabId) {
|
||||||
|
notifyTab(tab);
|
||||||
|
} else {
|
||||||
|
setTimeout(notifyTab, 0, tab);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// notify self: the message no longer is sent to the origin in new Chrome
|
// notify self: the message no longer is sent to the origin in new Chrome
|
||||||
|
|
Loading…
Reference in New Issue
Block a user