I’m working on a project using puppeteer-cluster and I need help setting up an endless loop for my tasks. I wrote some initial code, but after about 30 seconds of execution, the process becomes idle and stops responding as expected. My goal is to ensure that the cluster continuously processes tasks without interruption. Below is an example of my current approach, and I would appreciate any ideas on how to modify it so that the loop runs seamlessly without idling.
const { Cluster } = require('puppeteer-cluster');
(async () => {
const endlessCluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_PAGE,
maxConcurrency: 4
});
endlessCluster.task(async ({ page, data: targetUrl }) => {
await page.goto(targetUrl);
console.log(`Navigated to ${targetUrl}`);
});
// Running an infinite loop to continuously queue tasks
while (true) {
endlessCluster.queue('https://example.org');
await new Promise(resolve => setTimeout(resolve, 1000));
}
})();