Open Bug 1425216 Opened 7 years ago Updated 11 days ago

browser.webRequest.onCompleted response "tabId" value always -1

Categories

(WebExtensions :: Request Handling, defect, P3)

57 Branch
defect

Tracking

(Not tracked)

People

(Reporter: tlissak, Unassigned)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0 Build ID: 20171206182557 Steps to reproduce: Web Extension with background.js to monitor web requests. Simply those 2 files : manifest.json : { "manifest_version": 2, "name": "Test", "version": "1.0", "description": "Ex.", "permissions": ["tabs","webRequest","<all_urls>"], "background": { "scripts": ["background.js"] } } background.js : browser.webRequest.onCompleted.addListener( function (responseDetails) { var tabId = responseDetails.tabId ; console.log('tabId is :',tabId); // :( tabId == -1 in every tab request }, { urls: ["<all_urls>"] }); Since last update of Firefox (57.0.2) the value is wrong (initial release of firefox 57.0 have no issue) Actual results: Value of tabId is always returning -1. Expected results: tabId should return the current tab id value .
Component: Untriaged → WebExtensions: Request Handling
Product: Firefox → Toolkit
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Issue was fixed in FF 58.0
Product: Toolkit → WebExtensions
Severity: normal → S3

I see similar behavior in Firefox 117.0.
Some of completed requests tab have tabId -1.

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/onCompleted#details_2

Is this issue open or should I create a new bug?

Example debug extension console log:
Request happened for tabId: 42 background.js:3:7
Request happened for tabId: -1 background.js:3:7
Request happened for tabId: 42 16 background.js:3:7
Request happened for tabId: -1 2 background.js:3:7
Request happened for tabId: 42 6 background.js:3:7
Request happened for tabId: -1 background.js:3:7
Request happened for tabId: 42 background.js:3:7
Request happened for tabId: -1 background.js:3:7
Request happened for tabId: 42 2 background.js:3:7
Request happened for tabId: -1 background.js:3:7
Request happened for tabId: 42 background.js:3:7
Request happened for tabId: -1 background.js:3:7
Request happened for tabId: 42 background.js:3:7
Request happened for tabId: -1 background.js:3:7
Request happened for tabId: 42 22 background.js:3:7
Request happened for tabId: -1 background.js:3:7
Request happened for tabId: 42 2 background.js:3:7
Request happened for tabId: -1 background.js:3:7
Request happened for tabId: 42 13 background.js:3:7
Request happened for tabId: -1 2 background.js:3:7
Request happened for tabId: 42 2 background.js:3:7
Request happened for tabId: -1 2 background.js:3:7
Request happened for tabId: 42 5 background.js:3:7
Request happened for tabId: -1 background.js:3:7
Request happened for tabId: 42 3 background.js:3:7
Request happened for tabId: -1 background.js:3:7
Request happened for tabId: 42 11 background.js:3:7
Request happened for tabId: -1 background.js:3:7
Request happened for tabId: 42 22 background.js:3:7
Request happened for tabId: -1 3 background.js:3:7
Request happened for tabId: 42 background.js:3:7
Request happened for tabId: -1 5 background.js:3:7
Request happened for tabId: 42 8 background.js:3:7
Request happened for tabId: -1 background.js:3:7
Request happened for tabId: 42 3 background.js:3:7

I can confirm that this bug still exists in Firefox 130.0 (or was introduced back as a regression).
The tabId will only be set for additional requests that are caused by the request with type main_frame.

Strangely enough, adding an "empty" handler to the browser.webRequest.onResponseStarted fixes the issue:

browser.webRequest.onResponseStarted.addListener(
  () => {},
  { urls: ['<all_urls>'] }, // Listen to all URLs
   ['responseHeaders'],
);

I can only assume that the cause is a race condition that is fixed by the slight delay introduced by the additional handler.
The bug only occured in a fresh Firefox profile. Upon further investigation I noticed that any other extension using the additional handler fixes the issue.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: