-
Notifications
You must be signed in to change notification settings - Fork 937
Expand file tree
/
Copy pathchrome-path.ts
More file actions
64 lines (54 loc) · 1.97 KB
/
chrome-path.ts
File metadata and controls
64 lines (54 loc) · 1.97 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { existsSync } from 'node:fs';
import { MIDSCENE_MCP_CHROME_PATH, globalConfigManager } from '../env';
let cachedSystemChromePath: string | undefined = undefined;
export function clearSystemChromePathCache() {
cachedSystemChromePath = undefined;
}
export function getSystemChromePath(): string | undefined {
if (cachedSystemChromePath !== undefined) {
return cachedSystemChromePath;
}
const platform = process.platform;
const chromePaths: Record<string, string[]> = {
darwin: [
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
'/Applications/Chromium.app/Contents/MacOS/Chromium',
],
win32: [
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
`C:\\Users\\${process.env.USERNAME ?? process.env.USER}\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe`,
],
linux: [
// Prefer actual binaries over wrapper scripts.
// Wrappers in /usr/bin may strip --user-data-dir, causing
// "DevTools remote debugging requires a non-default data directory" errors.
'/opt/google/chrome/chrome',
'/opt/google/chrome/google-chrome',
'/usr/bin/google-chrome-stable',
'/usr/bin/google-chrome',
'/usr/bin/chromium-browser',
'/usr/bin/chromium',
'/snap/bin/chromium',
],
};
const paths = chromePaths[platform] ?? [];
const foundPath = paths.find((p) => existsSync(p));
if (foundPath) {
cachedSystemChromePath = foundPath;
}
return foundPath;
}
export function resolveChromePath(): string {
const envPath = globalConfigManager.getEnvConfigValue(
MIDSCENE_MCP_CHROME_PATH,
);
if (envPath && envPath !== 'auto' && existsSync(envPath)) {
return envPath;
}
const systemPath = getSystemChromePath();
if (systemPath) return systemPath;
throw new Error(
'Chrome not found. Install Google Chrome or set MIDSCENE_MCP_CHROME_PATH environment variable.',
);
}