Closed Bug 1738877 Opened 4 years ago Closed 4 years ago

Warn on badly used browser.webRequest.filterResponseData

Categories

(WebExtensions :: Request Handling, enhancement)

Firefox 94
enhancement

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: michalwadas, Unassigned)

Details

(Keywords: dev-doc-complete)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0

Steps to reproduce:

I had following code:

window.browser.webRequest.onBeforeRequest.addListener(
(details) => {
const filter = window.browser.webRequest.filterResponseData(details.requestId);
if (!details.url.includes('/some/url')) {
return;
}
filter.ondata ...
})

Actual results:

All requests not-matching /some/url silently failed.

Expected results:

I would expect warning.

Another option would be to extend signature of browser.webRequest.filterResponseData with second argument in form of:

{
        ondata?: (data: StreamFilterEventData) => void;
        onstart?: (data: StreamFilterEventData) => void;
        onstop?: (data: StreamFilterEventData) => void;
        onerror?: (data: StreamFilterEventData) => void;
}

The Bugbug bot thinks this bug should belong to the 'WebExtensions::Request Handling' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.

Component: Untriaged → Request Handling
Product: Firefox → WebExtensions

This is not a defect with the API, but a bug with the extension. We cannot guess the intent of the extension, but we could try to improve docs to help extension developers to do the right thing.

The documentation can be improved to emphasize that once the filterResponseData has been created, that the extension is given full control over response, and that it should have an ondata listener to process the stream (even if it's just filter.write(event.data)) and the extension should be calling close() or disconnect().

Richard, could you improve the docs?

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/filterResponseData
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/StreamFilter

Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Flags: needinfo?(richard)
Keywords: dev-doc-needed
Resolution: --- → WONTFIX

I've created Clarify behavior of webRequest.filterResponseData() #10432 to cover this requirement.

Flags: needinfo?(richard)
Keywords: dev-doc-needed

This is not a defect with the API, but a bug with the extension.

I would argue that well designed API should be hard to misuse. If it's necessary to register events on event listener, event registration should be possible in .filterResponseData.

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