-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlauncher.ts
More file actions
40 lines (33 loc) · 1011 Bytes
/
launcher.ts
File metadata and controls
40 lines (33 loc) · 1011 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
39
40
import { spawn } from "child_process";
import { platform } from "os";
import { detectBrowser } from "./detector";
const launchBrowser = (port: number = 3005, browser?: string | null) => {
try {
const chromePath = browser ? browser : detectBrowser();
if (!chromePath) {
throw new Error(
"Chrome/Chromium not found. Please install Google Chrome or Chromium."
);
}
console.log(`Launching Chrome from: ${chromePath}`);
const openBrowser = spawn(
chromePath,
[
`--remote-debugging-port=${port}`,
"--user-data-dir=/tmp/chrome-profile",
],
{
detached: true,
stdio: "ignore",
shell: platform() === "win32",
}
);
openBrowser.unref();
console.log("Chrome launched with PID:", openBrowser.pid);
return new Promise((resolve) => setTimeout(resolve, 2000));
} catch (error) {
console.error("Error launching browser:", error);
process.exit(1);
}
};
export default launchBrowser;