-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathscreenshot.js
More file actions
54 lines (43 loc) · 1.33 KB
/
screenshot.js
File metadata and controls
54 lines (43 loc) · 1.33 KB
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
46
47
48
49
50
51
52
53
54
const puppeteer = require("puppeteer-core");
const next = require("next/dist/server/lib/start-server");
async function main() {
const app = await next.startServer({
dir: __dirname,
hostname: "localhost",
port: 3000,
dev: true,
});
const appUrl = `http://${app.hostname}:${app.port}`;
console.log(`started server on ${app.port}, url: ${appUrl}`);
await app.prepare();
console.log("launching browser ");
const browser = await puppeteer.launch({
headless: true,
});
const page = await browser.newPage();
await page.setViewport({
width: 1280,
height: 720,
deviceScaleFactor: 2,
});
await page.emulateMediaFeatures([
{ name: "prefers-color-scheme", value: "dark" },
{ name: "prefers-reduced-motion", value: "reduce" },
]);
console.log("opening page");
await page.goto("http://localhost:3000/", { waitUntil: "networkidle0" });
await page.evaluate((_) => {
document.querySelectorAll('[loading="lazy"]').forEach((x) => {
x.attributes.removeNamedItem("loading");
});
});
await page.waitForTimeout(500);
await page.waitForNetworkIdle();
console.log("taking screenshot");
await page.screenshot({ path: __dirname + "/out/README.png", captureBeyondViewport: true, fullPage: true, type: "png" });
console.log("done. closing browser + server");
await app.close();
await browser.close();
process.exit();
}
main();