Skip to content

Commit b7a2eb7

Browse files
authored
Merge pull request #77 from UTDNebula/gcp-runner-fixes
Improve headless mode
2 parents dffe29a + ca37991 commit b7a2eb7

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23 AS builder
1+
FROM golang:1.24 AS builder
22

33
WORKDIR /app
44
COPY . .

utils/methods.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ func GetEnv(name string) (string, error) {
3838
func InitChromeDp() (chromedpCtx context.Context, cancelFnc context.CancelFunc) {
3939
log.Printf("Initializing chromedp...")
4040
if Headless {
41-
chromedpCtx, cancelFnc = chromedp.NewContext(context.Background())
41+
opts := append(chromedp.DefaultExecAllocatorOptions[:],
42+
chromedp.Flag("headless", true),
43+
chromedp.Flag("no-sandbox", true),
44+
chromedp.Flag("disable-dev-shm-usage", true),
45+
chromedp.Flag("disable-gpu", true),
46+
)
47+
allocCtx, _ := chromedp.NewExecAllocator(context.Background(), opts...)
48+
chromedpCtx, cancelFnc = chromedp.NewContext(allocCtx)
4249
} else {
4350
allocCtx, _ := chromedp.NewExecAllocator(context.Background())
4451
chromedpCtx, cancelFnc = chromedp.NewContext(allocCtx)
@@ -164,10 +171,12 @@ func RefreshAstraToken(chromedpCtx context.Context) map[string][]string {
164171

165172
// Save all cookies to string
166173
cookieStr := ""
167-
_, err = chromedp.RunResponse(chromedpCtx,
168-
chromedp.WaitVisible(`body`, chromedp.ByQuery),
174+
err = chromedp.Run(chromedpCtx,
169175
chromedp.ActionFunc(func(ctx context.Context) error {
170176
cookies, err := network.GetCookies().Do(ctx)
177+
if err != nil {
178+
return err
179+
}
171180
gotToken := false
172181
for _, cookie := range cookies {
173182
cookieStr = fmt.Sprintf("%s%s=%s; ", cookieStr, cookie.Name, cookie.Value)
@@ -179,7 +188,7 @@ func RefreshAstraToken(chromedpCtx context.Context) map[string][]string {
179188
if !gotToken {
180189
return errors.New("failed to get a new token")
181190
}
182-
return err
191+
return nil
183192
}),
184193
)
185194
if err != nil {

0 commit comments

Comments
 (0)