Hello,
I’m writing simple add on that uses WebExtensions API. Currently I have one background script that registers listeners for various webRequest
events (onBeforeRequest
and onResponseStarted
).
When visiting website (html + css or js) it sometimes happens, that onBeforeRequest
is fired for all request types: main_frame
, stylesheet
, etc. but no corresponding onResponseStarted
event is fired for request of typemain_frame
. When I reload the same page all events are fired for given url as documented at https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest. It looks a bit random to me but this may only be my impression.
Is that expected that not all events are fired at various stages of making an HTTP request for certain request types like main_frame
or is it a bug? Where can I find more info about when exactly onResponseStarted
would not be fired?
Here is my sample code from background.js
script
const requestFilter = { urls: ['<all_urls>'] }
browser.webRequest.onBeforeRequest.addListener(details => {
if (details.type === 'main_frame') {
console.log(`onBeforeRequest: ${details.url}`)
}
}, requestFilter)
browser.webRequest.onResponseStarted.addListener(details => {
if (details.type === 'main_frame') {
console.log(`onResponseStarted: ${details.url}`)
}
}, requestFilter)