@@ -38,7 +38,14 @@ func GetEnv(name string) (string, error) {
3838func 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