-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
74 lines (69 loc) · 1.96 KB
/
path.go
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
65
66
67
68
69
70
71
72
73
74
// Copyright 2021 Wayback Archiver. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package helper // import "github.com/wabarc/helper"
import (
"os"
"os/exec"
"path/filepath"
"runtime"
)
// FindChromeExecPath tries to find the Chrome browser somewhere in the current
// system. It finds in different locations on different OS systems.
// It could perform a rather aggressive search. That may make it a bit slow,
// but it will only be run when creating a new ExecAllocator.
// Fork from: https://github.com/chromedp/chromedp/blob/4ea2300cf7c7065242867bdcb8772533e0a66ea7/allocate.go#L352-L383
func FindChromeExecPath() string {
if path := os.Getenv("CHROME_BIN"); path != "" {
found, err := exec.LookPath(path)
if err == nil {
return found
}
}
var locations []string
switch runtime.GOOS {
case "darwin":
locations = []string{
// Mac
"chrome",
"chromium",
"/Applications/Chromium.app/Contents/MacOS/Chromium",
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
}
case "windows":
locations = []string{
// Windows
"chrome",
"chromium",
"chrome.exe", // in case PATHEXT is misconfigured
`C:\Program Files (x86)\Google\Chrome\Application\chrome.exe`,
`C:\Program Files\Google\Chrome\Application\chrome.exe`,
filepath.Join(os.Getenv("USERPROFILE"), `AppData\Local\Google\Chrome\Application\chrome.exe`),
}
default:
locations = []string{
// Unix-like
"headless_shell",
"headless-shell",
"chromium",
"chromium-browser",
"google-chrome",
"google-chrome-stable",
"google-chrome-beta",
"google-chrome-unstable",
"/usr/bin/google-chrome",
"/usr/local/bin/chrome",
"/snap/bin/chromium",
"chrome",
}
}
for _, path := range locations {
found, err := exec.LookPath(path)
if err == nil {
return found
}
}
// Fall back to something simple and sensible, to give a useful error
// message.
return "google-chrome"
}