This repository has been archived by the owner on Jul 21, 2022. It is now read-only.
forked from rsamec/karma-puppeteer-launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chrome.js
64 lines (57 loc) · 1.75 KB
/
chrome.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
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
var fsAccess = require('fs-access')
var path = require('path')
var which = require('which')
// Return location of chrome.exe file for a given Chrome directory (available: "Chrome", "Chrome SxS").
function getChromeExe(chromeDirName) {
// Only run these checks on win32
if (process.platform !== 'win32') {
return null
}
var windowsChromeDirectory, i, prefix
var suffix = '\\Google\\' + chromeDirName + '\\Application\\chrome.exe'
var prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']]
for (i = 0; i < prefixes.length; i++) {
prefix = prefixes[i]
try {
windowsChromeDirectory = path.join(prefix, suffix)
fsAccess.sync(windowsChromeDirectory)
return windowsChromeDirectory
} catch (e) { }
}
return windowsChromeDirectory
}
function getBin(commands) {
// Don't run these checks on win32
if (process.platform !== 'linux') {
return null
}
var bin, i
for (i = 0; i < commands.length; i++) {
try {
if (which.sync(commands[i])) {
bin = commands[i]
break
}
} catch (e) { }
}
return bin
}
function getChromeDarwin(defaultPath) {
if (process.platform !== 'darwin') {
return null
}
try {
var homePath = path.join(process.env.HOME, defaultPath)
fsAccess.sync(homePath)
return homePath
} catch (e) {
return defaultPath
}
}
module.exports = {
// Try chromium-browser before chromium to avoid conflict with the legacy
// chromium-bsu package previously known as 'chromium' in Debian and Ubuntu.
linux: getBin(['chromium-browser', 'chromium', 'google-chrome', 'google-chrome-stable']),
darwin: getChromeDarwin('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'),
win32: getChromeExe('Chrome')
}