-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (47 loc) · 1.45 KB
/
index.js
File metadata and controls
50 lines (47 loc) · 1.45 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
import {chromium} from "playwright-core";
import {exec} from 'node:child_process';
const startPlaywrightServer = async () => {
const headless =true;
const isCI = false;
const args = [];
if (isCI) {
args.push('--no-sandbox', '--disable-setuid-sandbox');
}
if (headless) {
args.push('--headless');
}
return chromium.launchServer({
headless,
args
});
};
let browserServer, wsEndpoint, browser, page, dev;
try {
browserServer = await startPlaywrightServer();
wsEndpoint = browserServer.wsEndpoint();
browser = await chromium.connect(wsEndpoint);
page = await browser.newPage();
console.log(`trying page.goto with https://playwright.dev`);
await page.goto('https://playwright.dev');
console.log('SUCCESS')
const url = 'http://localhost:5173';
console.log(`starting vite dev server on ${url}`)
dev = exec('vite dev');
// wait a bit so vite devserver is started
await new Promise(resolve => {setTimeout(resolve,500)})
await fetch(url).then(res => res.text()).then(text => {
console.log(`fetched ${url}\n`, text);
});
console.log(`trying page.goto with ${url}`)
await page.goto(url); // this fails
console.log('SUCCESS')
} catch (e) {
console.error('ERROR',e);
} finally {
await Promise.allSettled([
dev?.kill('SIGTERM'),
page?.close(),
browser?.close(),
browserServer.close()
].filter(Boolean))
}