Hi all,
I have written a tiny demo extension that uses “browser.webRequest.onBeforeRequest.addListener” and inside the listener performs “browser.webRequest.filterResponseData(details.requestId);”. This works like expected (e.g. like the webextensions-examples/http-response). Now, I noticed that for service workers registered via “navigator.serviceWorker.register” in the filtered web page, the web extension is blind. It sees the url of the service worker but does not receive the necessary events to filter the data. Is this behavior expected (e.g. security considerations) or is it a bug?
To filter what data? The data that the service worker retrieves from cache using https://developer.mozilla.org/en-US/docs/Web/API/Cache and answers requests with? Because that’s expected behavior, webRequest only allows you to filter requests that hit the network.
Hi again,
here is the problem again but with a bit more details. Some excerpt of a minimal background.js. This is registered via “browser.webRequest.onBeforeRequest.addListener” :
function listener(details) {
console.log("–> Req url:"+ details.url + " "+ details.type+ " “+ details.requestId);
let filter = browser.webRequest.filterResponseData(details.requestId);
…
filter.ondata = event => {
currentData = decoder.decode(event.data, {stream: true});
body += currentData;
filter.write(encoder.encode(currentData));
}
…
filter.onerror = event => {
console.log(--> Error: ${filter.error} for ${details.requestId});
}
…
filter.onstop = async _ => {
…
console.log(”<-- Checksum: " + details.url+ " " + bodyHash);
}
return {};
}
Assume we have a minimal web site:
index.html --> ref to loadsw.js
loadsw.js --> preforms register sw
/sw-test/sw.js --> service worker
Next we register a service worker … loadsw.js:1:9
–> Req url:http://127.0.0.1:8080/sw-test/sw.js script 106 background.js:13:11
–> Error: Invalid request ID for 106 background.js:28:10
^^^^^^^^^^^^^^^
Thus the service worker (sw.js) is noticed as a url that is requested in the web extension but the response to this request cannot be inspected and I get an “Invalid request ID” error.