Skip to content

Instantly share code, notes, and snippets.

@apoorva-shah
Created January 1, 2020 12:53
Show Gist options
  • Save apoorva-shah/ceb4cd482db66d13782367852efda0f6 to your computer and use it in GitHub Desktop.
Save apoorva-shah/ceb4cd482db66d13782367852efda0f6 to your computer and use it in GitHub Desktop.
puppeteer cluster page close issue
// Page should close after 2 mins but it is closed after ~27 seconds...
const { Cluster } = require('puppeteer-cluster');
(async () => {
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_CONTEXT,
maxConcurrency: 2,
puppeteerOptions: {
headless: false
}
});
// We don't define a task and instead queue individual functions
// Make a screenshot
cluster.queue(async ({ page }) => {
console.log('inside');
await page.goto('http://www.wikipedia.org');
await new Promise(resolve => {
setTimeout(() => { // user is waiting for an asynchronous event
console.log('after 2 mins now close');
resolve();
}, 120 * 1000);
});
});
await cluster.idle();
await cluster.close();
})();
const timeout = millis => new Promise(resolve => setTimeout(resolve, millis));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment