"permanent"/global Variable in http RequestListener?

33 views
Skip to first unread message

densch123

unread,
Sep 24, 2022, 12:56:33 PM9/24/22
to Chromium Extensions
Hi, In my currently developing add-on I have these bits of code:

manifest.json:

bg.js:
https://pastebin.com/SEG9G68e

write.js:
https://pastebin.com/rB3F4Ftq

According to my knowledge
bg.js somehow "injects" the javascript stuff from write.js into the website.
Dont ask me how since I dont understand any of what is happening.

All I know is thta the code in write.js is somehow catching all http requests and response and that I can do stuff with those infos.

now what I am hoping to get some info about:
1.how and where can I do "normal" javascript stuff, like writing functiopns and such?

Would that have to placed in the write.js file but outside the whole function(xhr) block?

2. as I said with each request and response pair I get access to that current requests data.

however that stuff is temporary and jsut gone the second that request is processed or at latest gone once the second request comes in.

this for me is a problem.

cause what I wanna do right now:
in some requests, in their corresponding response, there is an integer value called balance.
getting that number from a given request isnt the problem.

now I wanna check if for a given request+response, if said balance value has changed in comparision to the previous balance value and if so by what.

in java for that II would have have a global variable "previousbalance" wher... you guessed it... the previous requests balance number is saved.
and in the current request, I would then jsut do something like
difference=this_requests_balance-previousbalance
to see how the number has changed from last request to this.

but in my given javascript code how or where can I place and define such a "global" variable that persist over different request capture actions and that can be modified during each request capture, namely can be accessed from inside the function(xhr) in write.js?


I really hope someone can help me there, since I dont really get most of what is happening or how it works :-)

wOxxOm

unread,
Sep 24, 2022, 7:35:45 PM9/24/22
to Chromium Extensions, schue...@gmail.com
You can declare your variables in the same place at the beginning with all the `var` statements.
Reply all
Reply to author
Forward
0 new messages