-
Notifications
You must be signed in to change notification settings - Fork 0
/
chromePath.js
37 lines (34 loc) · 956 Bytes
/
chromePath.js
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
/**
* Get the path to the chrome executable for current OS.
* If the path is not found, catch the error and return null.
*/
const getChromePath = () => {
let chromePath = null;
try {
switch (process.platform) {
case "win32":
chromePath =
"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
break;
case "linux":
chromePath = "/usr/bin/google-chrome";
break;
case "darwin":
chromePath =
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";
break;
default:
throw new Error("Unsupported platform: " + process.platform);
}
// check if chromePath is valid and exists
const fs = require("fs");
if (fs.existsSync(chromePath)) {
return chromePath;
} else {
throw new Error("Chrome path is invalid");
}
} catch (err) {
console.log(err);
}
};
exports.getChromePath = getChromePath;