1

I am trying to do something very similar to this thread, except that instead of XHR, the web app (written in React) uses the Fetch API to do its asynchronous calls.

Is there an elegant way to intercept/overwrite fetch? Basically I want to see each AJAX call the site is doing and grab the data from there. I could just grab it as shown on the site after the fact, but we all know that JSON is easier than HTML to deal with. The site is STATEFUL, so I cannot just resend the URL.

I tried just writing a wrapper like:

function replaceFetch(){
    (function(window, debug){
        var _fetch = window.fetch;

        window.fetch = function(u, o = {}) {
            console.log("This is a test");
            return _fetch(u, o);
        }

    })(window, false);
};

casper.on("page.initialized", function(resource){
    this.evaluate(replaceFetch);
});

But I get "Untitled suite" error, and can't find anything I can require() to implement Fetch.

Any thoughts? Thanks!

Community
  • 1
  • 1
seapigg
  • 11
  • 1
  • `window.fetch()` only has two functions AFAICS, so it should be even easier to proxy than XMLHttpRequest. – Artjom B. Apr 05 '16 at 19:31

0 Answers0