diff --git a/client/auth.go b/client/auth.go index 68e9363..ca32814 100644 --- a/client/auth.go +++ b/client/auth.go @@ -11,6 +11,7 @@ import ( "io" "net/http" "net/url" + "os/exec" "strings" "time" ) @@ -125,9 +126,24 @@ func isTokenValid(user *db.User) bool { return time.Now().Before(expiresAt) } -// createChromeContext creates a ChromeDP context with the specified headless option. +// createChromeContext creates a new ChromeDP context. func createChromeContext(headless bool) (context.Context, context.CancelFunc) { - opts := chromedp.DefaultExecAllocatorOptions[:] + // Check if Google Chrome or Chromium is available in the path + var execPath string + if path, err := exec.LookPath("google-chrome"); err == nil { + execPath = path + } else if path, err := exec.LookPath("chromium"); err == nil { + execPath = path + } else if path, err := exec.LookPath("chrome"); err == nil { + execPath = path + } else { + log.Error().Msg("Neither Google Chrome nor Chromium is available in the path. Please install one of them.") + return nil, nil + } + + opts := append(chromedp.DefaultExecAllocatorOptions[:], + chromedp.ExecPath(execPath), + ) if !headless { opts = append(opts, chromedp.Flag("headless", false), chromedp.Flag("disable-gpu", false), chromedp.Flag("start-maximized", true))