diff --git a/internal/suites/utils.go b/internal/suites/utils.go index 6d96d05ec..df4fb4f18 100644 --- a/internal/suites/utils.go +++ b/internal/suites/utils.go @@ -18,6 +18,38 @@ import ( "github.com/google/uuid" ) +var browserPaths = []string{"/usr/bin/chromium-browser", "/usr/bin/chromium"} + +// ValidateBrowserPath validates the appropriate chromium browser path. +func ValidateBrowserPath(path string) (browserPath string, err error) { + var info os.FileInfo + + if info, err = os.Stat(path); err != nil { + return "", err + } else if info.IsDir() { + return "", fmt.Errorf("browser cannot be a directory") + } + + return path, nil +} + +// GetBrowserPath retrieves the appropriate chromium browser path. +func GetBrowserPath() (path string, err error) { + browserPath := os.Getenv("BROWSER_PATH") + + if browserPath != "" { + return ValidateBrowserPath(browserPath) + } + + for _, browserPath = range browserPaths { + if browserPath, err = ValidateBrowserPath(browserPath); err == nil { + return browserPath, nil + } + } + + return "", fmt.Errorf("no chromium browser was detected in the known paths, set the BROWSER_PATH environment variable to override the path") +} + // GetLoginBaseURL returns the URL of the login portal and the path prefix if specified. func GetLoginBaseURL(baseDomain string) string { if PathPrefix != "" { diff --git a/internal/suites/webdriver.go b/internal/suites/webdriver.go index 79d0d94ad..da14b607b 100644 --- a/internal/suites/webdriver.go +++ b/internal/suites/webdriver.go @@ -19,10 +19,11 @@ type RodSession struct { } // StartRodWithProxy create a rod/chromedp session. -func StartRodWithProxy(proxy string) (*RodSession, error) { - browserPath := os.Getenv("BROWSER_PATH") - if browserPath == "" { - browserPath = "/usr/bin/chromium-browser" +func StartRodWithProxy(proxy string) (session *RodSession, err error) { + var browserPath string + + if browserPath, err = GetBrowserPath(); err != nil { + return nil, err } headless := false