-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathskeleton.js
40 lines (38 loc) · 1.53 KB
/
skeleton.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
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Skeleton for Web Screenshot Service using Puppeteer-Cluster and PDF generation.
* Students: Fill in the missing pieces (e.g., concurrency options, PDF creation steps, etc.).
*/
const { Cluster } = require("puppeteer-cluster");
// TODO: import fs, path, and pdf-lib (PDFDocument) libraries if you need them
(async () => {
try {
// 1. Create necessary directories (screenshotsDir)
// HINT: Use fs.existsSync(...) and fs.mkdirSync(...)
// 2. Launch the Puppeteer-Cluster with the desired concurrency
// Example:
// const cluster = await Cluster.launch({
// // concurrency: Cluster.CONCURRENCY_BROWSER,
// // maxConcurrency: 3,
// // puppeteerOptions: { headless: true }
// });
// 3. Define the cluster task to visit each URL and capture a screenshot
// Example:
// await cluster.task(async ({ page, data: url }) => {
// // ...
// });
// 4. Queue up a few URLs
// Example:
// const urls = ["https://example.com"];
// urls.forEach(url => cluster.queue(url));
// 5. Wait for cluster tasks to complete
// await cluster.idle();
// await cluster.close();
// 6.(OPTIONAL) Generate a PDF from the captured images
// HINT: Use the PDFDocument from pdf-lib
// 7. (OPTIONAL)Clean up the screenshots folder
// HINT: Use fs.unlinkSync(...) if needed
// 8. Everytime you generate a pdf try naming it with a unique name and can embed the timestamp in the name
} catch (error) {
console.error("An error occurred in the skeleton script:", error);
}
})();