Created
January 1, 2020 12:53
-
-
Save apoorva-shah/ceb4cd482db66d13782367852efda0f6 to your computer and use it in GitHub Desktop.
puppeteer cluster page close issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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