Currently it seems the default behaviour of puppeteer is to follow redirects and return the DOM at the end of the chain.
How can I make the .goto()
method to stop after the first redirect happened and simply return the html from that first 3xx page when i call page.content() method?
You can enable a request interception and abort additional requests if a chain of requests is identified:
await page.setRequestInterception(true);
page.on('request', request => {
if (request.isNavigationRequest() && request.redirectChain().length !== 0) {
request.abort();
} else {
request.continue();
}
});
await page.goto('https://www.example.com/');
It seems that at the moment of writing, this is not possible (at least not in the high-level API that Puppeteer provides). Check out the docs for goto
here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With