Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
habedi committed Jan 17, 2025
1 parent 76f2b57 commit 7fabccc
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions client/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"net/http"
"net/url"
"os/exec"
"strings"
"time"
)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 7fabccc

Please sign in to comment.