forked from thomasdondorf/puppeteer-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimal.js
27 lines (22 loc) · 805 Bytes
/
minimal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const { Cluster } = require('../dist');
(async () => {
// Create a cluster with 2 workers
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_CONTEXT,
maxConcurrency: 2,
});
// Define a task (in this case: screenshot of page)
await cluster.task(async ({ page, data: url }) => {
await page.goto(url);
const path = url.replace(/[^a-zA-Z]/g, '_') + '.png';
await page.screenshot({ path });
console.log(`Screenshot of ${url} saved: ${path}`);
});
// Add some pages to queue
cluster.queue('https://www.google.com');
cluster.queue('https://www.wikipedia.org');
cluster.queue('https://github.com/');
// Shutdown after everything is done
await cluster.idle();
await cluster.close();
})();