Cancel redirects for the same requestIds and urls if originating from the same tabId #1120
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As mentioned in #1114 there are still cases where two tabs are opened when redirects are involved:
In this case
www.youtube.com
is assigned. The initial request goes tohttp://youtube.com
which results in redirects tohttps://youtube.com
and two timeshttps://www.youtube.com
- the last request has a differentrequestId
. All have the sametabId
.To fix this all requestIds and urls that reach the point of being "reopened" are marked as canceled in relation to the tabId - or are canceled if already marked as canceled. Instead of cleaning up canceled requests with a timeout, we can use
webRequest.onCompleted
andwebRequest.onErrorOccurred
- though, since they are not 100% reliable, a 2seconds backup cleanup timer is included (uncanceling is also covered with tests).The downside of this fix is that, if the user left clicks
http://youtube.com
on a website and switches back to the website, while the confirm page or target container is loading and the completed callback, error callback and backup cleanup timer haven't fired, then all clicks in that tab on the urls marked as canceled will be canceled. I'd personally say that is highly unlikely - the requests complete normally really fast, unless the user has a really slow internet-connection, and even if not after 2seconds the requests get uncanceled - and still preferable in comparison to two tabs opening at random.Fixes #940 #1003 #1080 #728 #912
Some informations when and how the redirects happen:
First time with clean Network cache in Firefox. 3 requests, all have the same requestId
Second time with filled Network cache in Firefox, 4 requests, last has a different requestId
Filed a Firefox bug since I believe this is not intended behavior. If the requestId wouldn't change or we had a way of correlating the two requests, this fix could be made side-effect-free.