-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathplaywright-script.js
More file actions
38 lines (29 loc) · 939 Bytes
/
playwright-script.js
File metadata and controls
38 lines (29 loc) · 939 Bytes
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
import { chromium } from 'playwright';
import path from 'path';
import fs from 'fs';
(async () => {
const url = process.argv[2];
const videoDir = path.resolve('./videos');
if (!fs.existsSync(videoDir)) {
fs.mkdirSync(videoDir, { recursive: true });
}
const browser = await chromium.launch({ args: ['--no-sandbox'] });
const context = await browser.newContext({
recordVideo: { dir: videoDir }
});
const page = await context.newPage();
let errors = [];
page.on('console', msg => {
if (msg.type() === 'error') {
errors.push(msg.text());
}
});
try {
await page.goto(url, { waitUntil: 'networkidle', timeout: 10000 });
} catch (error) {
errors.push(`Page load error: ${error.message}`);
}
const video = await page.video().path();
await browser.close();
console.log(JSON.stringify({ errors, video }));
})();