-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudit-screenshots.mjs
More file actions
49 lines (41 loc) · 1.44 KB
/
Copy pathaudit-screenshots.mjs
File metadata and controls
49 lines (41 loc) · 1.44 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
import { chromium } from 'playwright';
import { mkdir } from 'node:fs/promises';
await mkdir('screenshots/audit', { recursive: true });
const browser = await chromium.launch();
const context = await browser.newContext({
viewport: { width: 1440, height: 900 },
deviceScaleFactor: 1,
});
const page = await context.newPage();
const pages = [
{ url: 'http://localhost:4200/', name: 'home' },
{ url: 'http://localhost:4200/platform', name: 'platform' },
{ url: 'http://localhost:4200/get-started', name: 'get-started' },
];
for (const { url, name } of pages) {
console.log(`\n→ ${name}`);
await page.goto(url, { waitUntil: 'networkidle' });
await page.waitForTimeout(500);
// Viewport (above the fold)
await page.screenshot({
path: `screenshots/audit/${name}-fold.png`,
fullPage: false,
});
console.log(` ✓ fold`);
// Get total page height
const height = await page.evaluate(() => document.documentElement.scrollHeight);
const sectionHeight = 900;
const numSections = Math.ceil(height / sectionHeight);
// Screenshot each section by scrolling
for (let i = 0; i < numSections; i++) {
await page.evaluate((y) => window.scrollTo(0, y), i * sectionHeight);
await page.waitForTimeout(300);
await page.screenshot({
path: `screenshots/audit/${name}-s${i+1}.png`,
fullPage: false,
});
console.log(` ✓ section ${i+1}/${numSections}`);
}
}
await browser.close();
console.log('\n✓ done');