diff --git a/src/js/background/assignManager.js b/src/js/background/assignManager.js index 0051e09..86b9c3e 100644 --- a/src/js/background/assignManager.js +++ b/src/js/background/assignManager.js @@ -144,6 +144,21 @@ const assignManager = { return {}; } + // we decided to cancel the request at this point, register it as canceled request as early as possible + if (!this.canceledRequests[options.requestId]) { + this.canceledRequests[options.requestId] = true; + // register a cleanup for handled requestIds + // all relevant requests that come in that timeframe with the same requestId will be canceled + setTimeout(() => { + delete this.canceledRequests[options.requestId]; + }, 2000); + } else { + // if we see a request for the same requestId at this point then this is a redirect that we have to cancel to prevent opening two tabs + return { + cancel: true + }; + } + this.reloadPageInContainer(options.url, userContextId, siteSettings.userContextId, tab.index + 1, tab.active, siteSettings.neverAsk); this.calculateContextMenu(tab); @@ -174,6 +189,7 @@ const assignManager = { }); // Before a request is handled by the browser we decide if we should route through a different container + this.canceledRequests = {}; browser.webRequest.onBeforeRequest.addListener((options) => { return this.onBeforeRequest(options); },{urls: [""], types: ["main_frame"]}, ["blocking"]);