Skip to content

Commit 7dceaf6

Browse files
stoicallyjonathanKingston
authored andcommitted
Cancel requests with the same requestId
Prevents potential redirects from opening two tabs Closes #1114
1 parent 22ec01d commit 7dceaf6

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/js/background/assignManager.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,21 @@ const assignManager = {
144144
return {};
145145
}
146146

147+
// we decided to cancel the request at this point, register it as canceled request as early as possible
148+
if (!this.canceledRequests[options.requestId]) {
149+
this.canceledRequests[options.requestId] = true;
150+
// register a cleanup for handled requestIds
151+
// all relevant requests that come in that timeframe with the same requestId will be canceled
152+
setTimeout(() => {
153+
delete this.canceledRequests[options.requestId];
154+
}, 2000);
155+
} else {
156+
// 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
157+
return {
158+
cancel: true
159+
};
160+
}
161+
147162
this.reloadPageInContainer(options.url, userContextId, siteSettings.userContextId, tab.index + 1, tab.active, siteSettings.neverAsk);
148163
this.calculateContextMenu(tab);
149164

@@ -174,6 +189,7 @@ const assignManager = {
174189
});
175190

176191
// Before a request is handled by the browser we decide if we should route through a different container
192+
this.canceledRequests = {};
177193
browser.webRequest.onBeforeRequest.addListener((options) => {
178194
return this.onBeforeRequest(options);
179195
},{urls: ["<all_urls>"], types: ["main_frame"]}, ["blocking"]);

0 commit comments

Comments
 (0)