0

I've dug all the questions here, and, to proove the concept, what I've understood that if I want to catch a response from a request call - I have to alter the function that website implements. As I am not a front-ender, I do not quite understand the way it should be done...

I have the following code in Greasemonkey:

// ==UserScript==
// ==/UserScript==

(function() {
    let originalFetch = unsafeWindow.fetch;
    console.log(originalFetch);   //*1
  
    unsafeWindow.fetch = function monitorFetch (x, y){
        let response = originalFetch(x, y);
        let respo = response.clone();
        return response;
    };
  
    console.log(unsafeWindow.fetch);   //*2

The console from *1 prints

function monitorFetch (x, y)

and the console from *2 also prints

function monitorFetch (x, y)

But the website with this altering is not working - no thrown errors, I just see that requests that should be made are not being made.

I have also tried to find this original monitorFetch function in website javascript and copy-paste it into Greasemonkey - the same result: no errors, no requests made.

What I want - is just to catch the response, I don't even need to modify anything.

Question: what am I not understanding, or doing wrong, or not doing?

Versions: Greasemonkey v4.11 Firefox v81

Roman K.
  • 69
  • 6
  • Does this answer your question? [Intercept fetch() API requests and responses in JavaScript](https://stackoverflow.com/questions/45425169/intercept-fetch-api-requests-and-responses-in-javascript) – double-beep Dec 07 '21 at 20:58

1 Answers1

0

Nevermind.

In general - the question remains.

But as for this particular case of mine - I was lucky: the website saves the data I am looking for in unsafeWindow.localStorage.

Roman K.
  • 69
  • 6