Work with result from a http get

hello all
i´m new in addon development.
i try my first steps.
now i have my first question

i would like to get data out of a http get response and save it in storage local.

i check if it is the right web request
with this code

function logURL(requestDetails) {

if ( requestDetails.url.substring(0,33) ==‘https://www.website.com/data/json’ ) {
console.log("found: " + requestDetails.url);
}
}

browser.webRequest.onBeforeRequest.addListener(
logURL,
{urls: ["<all_urls>"]}
);

but how can i access the result from this get
it is a json format

thanks br marcus

1 Like

Hi, the server’s response is not yet available in onBeforeRequest, you need to listen for a later event.

Thanks for your answer.
i´m relative new in this development.
can you give me some hints oder a codefragment where i can see how i can access the data marked on the picture ?

thanks a lot

br caddy

This is a request made by the page? I don’t know how you access the body of the response, I’ve only worked with the headers.

Looks like you need to set up one of these:

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

2 Likes

great, i will have a look in it thanks

br caddy

thanks a lot. my addon is running.