How to Stop NodeJs Puppeteer Follow Redirects

Posted on September 13, 2019 at 10:22 am

Coupling setRequestInterception() with request.isNavigationRequest() and request.redirectChain() you can now abort navigation redirects in Puppeteer like this:

await page.setRequestInterception(true);
page.on('request', request => {
  if (request.isNavigationRequest() && request.redirectChain().length)
    request.abort();
  else
    request.continue();
});
await page.goto('https://example.com');

References:

https://github.com/GoogleChrome/puppeteer/issues/1132#issuecomment-393724933

Receive updates via email

Other Posts

Updated Posts