I'm trying to have a background script listen to responses, examine the data, and (once I've got this working), call make another request. I'm stuck on the first part, simply listening to the responses. I don't want to filter or change the responses, but it looks like webRequest.StreamFilter is the only way to monitor responses.
I have completed the 'your first extension' on the MDN site, read the relevant docs on background scripts, and looked at examples on mdn/webextensions-examples.
Here's my manifest.json and background script:
{
"manifest_version": 2,
"name": "MyResponseListener",
"version": "1.0",
"description": "Listens to responses.",
"icons": {
"48": "icons/border-48.png"
},
"background": {
"scripts": ["myReponseListener.js"]
},
"permissions" : [
"webRequest", "webRequestBlocking", "*://*.siteToListenTo.com/*"
]
}
Here's the script:
console.log("extension enabled")
function listener(details) {
let filter = browser.webRequest.filterResponseData(details.requestId);
filter.onstart = event => {
console.log("filter started");
}
filter.ondata = event => {
console.log("filter data : " + event.data);
}
filter.onstop = event => {
console.log("filter finished");
}
return {};
}
// have also tried this with types: ["main_frame"] as seen in some examples, but no difference
browser.webRequest.onCompleted.addListener(
listener,
{urls: ["https://siteToListenTo.com/*"]},
["blocking"]
);
It's not even printing the 'extension enabled' to the console. Not sure if I'm supposed to be looking at Browser console or Web Console in the developer tools.