-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
45 lines (40 loc) · 1.02 KB
/
worker.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
41
42
43
44
45
/* eslint-disable @typescript-eslint/no-var-requires */
const puppeteer = require("puppeteer");
const { parentPort } = require("worker_threads");
module.exports = async ({
url,
millisecondsArray,
width,
height,
quality,
headless,
}) => {
const browser = await puppeteer.launch({
args: ["--no-sandbox", "--disable-setuid-sandbox"],
headless: true,
});
const frames = [];
const page = await browser.newPage({ waitUntil: "networkidle2" });
await page.setViewport({
width,
height,
});
await page.goto(url, { waitUntil: "networkidle2" });
for (const ms in millisecondsArray) {
parentPort.postMessage({ increment: true });
await page.evaluate(
(millisecondsArray, ms) =>
window.document
.getElementsByTagName("donkey-clip")[0]
.setAttribute("ms", millisecondsArray[ms]),
millisecondsArray,
ms
);
const buffer = await page.screenshot({
type: "jpeg",
quality: quality,
});
frames.push(buffer);
}
return frames;
};