I have a simple Puppeteer-Cluster code written in NodeJS:
require("dotenv").config();
(async () => {
// Create a cluster with 2 workers
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_PAGE,
maxConcurrency: 2,
});
await cluster.task(async ({ page, data: link }) => {
let response = await page.goto(link);
statusCode = response.status();
var finalUrl = "";
try{
await page.waitForNavigation();
finalUrl = await page.evaluate(() => document.location.href);
} catch(error){
finalUrl = await page.evaluate(() => document.location.href);
}
});
cluster.queue(some_random_link);
await cluster.idle();
await cluster.close();
})();
If the try block is having some error, like a timeout, then the catch block is not being run. The page is simply terminated.
NOTE : When I run the same code using just normal Puppeteer, I have no issues. The issue is specifically with Puppeteer-Cluster.