webRequest.onBeforeRequest fires two different requestIds after redirect when network cache is filled

UNCONFIRMED
Unassigned
(NeedInfo from)

Status

()

Toolkit
WebExtensions: Request Handling
UNCONFIRMED
11 days ago
21 hours ago

People

(Reporter: stoically, Unassigned, NeedInfo)

Tracking

58 Branch
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

11 days ago
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
Build ID: 20180131010234

Steps to reproduce:

Registered webRequest listeners with WebExtension:

browser.webRequest.onBeforeRequest.addListener((details) => {
  console.log('incoming onBeforeRequest', details);
}, {
  urls: ['<all_urls>'],
  types: ['main_frame']
}, [
  'blocking',
  'requestBody'
]);
browser.webRequest.onBeforeRedirect.addListener((details) => {
  console.log('incoming onBeforeRedirect', details);
},  {
  urls: ['<all_urls>']
}, [
  'responseHeaders'
]);
browser.webRequest.onCompleted.addListener((details) => {
  console.log('incoming onCompleted', details);
},  {
  urls: ['<all_urls>'],
  types: ['main_frame']
}, [
  'responseHeaders'
]);


Actual results:

Clean profile, no network cache, navigating to http://youtube.com - all requests have the same requestId

incoming onBeforeRequest Object { requestId: "5503", url: "http://youtube.com/" .. }
incoming onBeforeRedirect Object { requestId: "5503", url: "http://youtube.com/" .. }
incoming onBeforeRequest Object { requestId: "5503", url: "https://youtube.com/" .. }
incoming onBeforeRedirect Object { requestId: "5503", url: "https://youtube.com/" .. }
incoming onBeforeRequest Object { requestId: "5503", url: "https://www.youtube.com/" .. }
incoming onCompleted Object { requestId: "5503", url: "https://www.youtube.com/" .. }

---

Second time navigating to http://youtube.com with filled cache. After redirecting the requestId changes

incoming onBeforeRequest Object { requestId: "5586", url: "http://youtube.com/" .. }
incoming onBeforeRequest Object { requestId: "5586", url: "https://youtube.com/" .. }
incoming onBeforeRedirect Object { requestId: "5586", url: "https://youtube.com/" .. }
incoming onBeforeRequest Object { requestId: "5586", url: "https://www.youtube.com/" .. }
incoming onBeforeRequest Object { requestId: "5587", url: "https://www.youtube.com/" .. }
incoming onCompleted Object { requestId: "5587" .. }


Expected results:

The requestId during the second navigation with filled cache should not change.

Couldn't find any other information regarding this and since the first navigation doesn't change the requestId and the second navigation doesn't fire onCompleted for the requestId 5586 I'm assuming this is not intended behavior. Also the requestId doesn't change in Chromium under the same circumstances.

This popped up while fixing a "two tabs randomly opening"-Issue with Multi-Account Containers (https://github.com/mozilla/multi-account-containers/pull/1120).
(Reporter)

Comment 1

10 days ago
Just to add, webRequest.onErrorOccurred doesn't see the request 5586 either - and without being able to correlate the two requests, it's afaik not possible to reliably cancel all requests that originate from the first 5586 request without checking for a combination of tabId and url, which could also affect other requests. In case of Multi-Account Container that would mean canceling clicks on the same link on the originating website.

Also tested with Firefox Nightly 60.0a1

Updated

10 days ago
Component: Untriaged → WebExtensions: Request Handling
Product: Firefox → Toolkit

Updated

21 hours ago
Flags: needinfo?(kmaglione+bmo)
You need to log in before you can comment on or make changes to this bug.