Skip to content

Commit fe035db

Browse files
committed
Improve headless mode
1 parent dffe29a commit fe035db

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

utils/methods.go

Lines changed: 12 additions & 2 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)
@@ -168,6 +175,9 @@ func RefreshAstraToken(chromedpCtx context.Context) map[string][]string {
168175
chromedp.WaitVisible(`body`, chromedp.ByQuery),
169176
chromedp.ActionFunc(func(ctx context.Context) error {
170177
cookies, err := network.GetCookies().Do(ctx)
178+
if err != nil {
179+
return err
180+
}
171181
gotToken := false
172182
for _, cookie := range cookies {
173183
cookieStr = fmt.Sprintf("%s%s=%s; ", cookieStr, cookie.Name, cookie.Value)
@@ -179,7 +189,7 @@ func RefreshAstraToken(chromedpCtx context.Context) map[string][]string {
179189
if !gotToken {
180190
return errors.New("failed to get a new token")
181191
}
182-
return err
192+
return nil
183193
}),
184194
)
185195
if err != nil {

0 commit comments

Comments
 (0)