-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_browser.js
More file actions
25 lines (20 loc) · 897 Bytes
/
Copy pathinit_browser.js
File metadata and controls
25 lines (20 loc) · 897 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
const { chromium } = require('playwright');
const fs = require('fs');
const path = require('path');
const SESSION_FILE = path.join(__dirname, 'session.json');
(async () => {
try {
const headless = process.env.HEADLESS === 'true';
console.log(`Launching browser server (headless: ${headless})...`);
const browserServer = await chromium.launchServer({ headless });
const wsEndpoint = browserServer.wsEndpoint();
const pid = browserServer.process().pid;
fs.writeFileSync(SESSION_FILE, JSON.stringify({ wsEndpoint, pid }));
console.log(`Browser server started with PID: ${pid}. Session saved.`);
console.log(`To close, run: "kill ${pid}" or use the "close" command.`);
// The active browserServer object should keep the process alive.
} catch (error) {
console.error(`Failed to launch browser server: ${error.message}`);
process.exit(1);
}
})();