Fix concurrency bug for completed request in inactive tab

This commit is contained in:
tunefish 2018-03-16 19:02:56 +01:00
parent 351feb4495
commit 0edb67224d

View file

@ -4,6 +4,7 @@ const messageHandler = {
// If this were in platform we would change how the tab opens based on "new tab" link navigations such as ctrl+click
LAST_CREATED_TAB_TIMER: 2000,
unhideQueue: [],
activeTab: -1,
init() {
// Handles messages from webextension code
@ -89,6 +90,7 @@ const messageHandler = {
browser.tabs.onActivated.addListener((info) => {
assignManager.removeContextMenu();
this.activeTab = info.tabId;
browser.tabs.get(info.tabId).then((tab) => {
assignManager.calculateContextMenu(tab);
}).catch((e) => {
@ -106,11 +108,15 @@ const messageHandler = {
}
assignManager.removeContextMenu();
browser.tabs.get(details.tabId).then((tab) => {
assignManager.calculateContextMenu(tab);
}).catch((e) => {
throw e;
});
// make sure to update the context menu only if the request was completed
// for the currently active tab
if (details.tabId === this.activeTab) {
browser.tabs.get(details.tabId).then((tab) => {
assignManager.calculateContextMenu(tab);
}).catch((e) => {
throw e;
});
}
}, {urls: ["<all_urls>"], types: ["main_frame"]});
browser.tabs.onCreated.addListener((tab) => {