-2

So I am not trying to bypass anything I just need to get the value returned by the request.

Example:

I go to a website.

Click a button.

Fill a RECAPTCHA

Once RECAPTCHA has been filled & verified it sends a request to an API with a payload & then the response returns a few values such as:

{"success":true,"data":{"signature":"SIG_K1_xxxxfp3w4EdhcCYqHwTntM19G7w4NCDt6ruTPistKPRow47cyeUiRMsc5YN9JMkqjtrfsk2Pf3nZkDY54rNWS5cyDhtE21y","nonce":1734981752}}

So I need to SOMEHOW grab the value of "signature" and "nonce" and again, I remind you, I AM NOT the one doing the FETCH request, the website/captcha is as soon as the captcha is validated. Is there anyway to do this?

PS: Before someone suggest that I do the FETCH request myself, I can't because it passes a "challenge" parameter in the payload which is unique to each RECAPTCHA and there's no way to find out its value.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
Steelhard2
  • 17
  • 2
  • @ggorlen That might be it although it looks incredibly complex, will have a look and try to figure out how it works, thank you so much! – Steelhard2 Jun 17 '21 at 17:18
  • With puppeteer? Use page.waitForResponse. – pguardiario Jun 18 '21 at 01:33
  • @pguardiario thank you I htink that'll do the trick. One more question, what code can I use to have puppeteer open the browser and then wait? I need to login to gmail account on it & do a few more stuff before I want it to run the script – Steelhard2 Jun 18 '21 at 06:36
  • You can wait for different things. Look at the puppeteer api for reference. – pguardiario Jun 18 '21 at 13:51

1 Answers1

0

You need to write an interceptor for this. The basic idea is that you take the function, that RECAPTCHA uses (which is either fetch or XMLHttpRequest), make a copy of the original, and write an interceptor that contains whatever you want to do with the data plus the original function.

For fetch something like this:

    const originalFetch = window.fetch;
    window.fetch = function() {
        return originalFetch.apply(this, arguments)
            .then((res) => {
                    res
                    .clone()
                    .json()
                    .then(data => {
                        console.log("fetch", data);
                    })
                    .catch(err => console.error(err));
                return res;
            });
    }

For XMLHttpRequest:

    const origOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function() {
            this.addEventListener('load', function() {
                console.log("open", JSON.parse(this.responseText))
            });
        origOpen.apply(this, arguments);
    };
    const origSend = XMLHttpRequest.prototype.send;
    XMLHttpRequest.prototype.send = function(data) {
            this.addEventListener('load', function() {
                console.log("send", data);
            });
        origSend.apply(this, arguments);
    };
Stiegi
  • 1,074
  • 11
  • 22
  • How do I choose whichever request to be the one I intercept? or does it intercept all requests starting from when that code runs? – Steelhard2 Jun 17 '21 at 20:09
  • It intercepts all of them. Have a look at the data you receive, I guess you'll find something that identifies the particular request you are interested in, so you can execute your handle behind an if statement – Stiegi Jun 17 '21 at 21:01