I am using Chromedp to post some stuff occasionally on Social Media. When I run the script in non-headless mode it is working perfect.
When I try to run it in headless mode, nothing happens. Obviously something is going wrong, but since I cannot "see" what is going wrong I am clueless.
Can anyone tell me how one should debug something when not able to visually see what Chromedp is doing?
And maybe explain to me why non-headless is working but headless not, because I do not understand how that can be.
I tried it with this code (minimized it), and in non-headless it works perfect. As soon as I go headless is doesn't do anything.
opts := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.Flag("headless", false),
)
actx, acancel := chromedp.NewExecAllocator(context.Background(), opts...)
defer acancel()
ctx, cancel := chromedp.NewContext(
actx,
chromedp.WithLogf(log.Printf),
)
defer cancel()
ctx, cancel = context.WithTimeout(ctx, 120*time.Second)
defer cancel()
err = chromedp.Run(ctx,
emulation.SetUserAgentOverride("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0"),
//chromedp.ResetViewport(),
chromedp.Navigate("https://example.com/"),
chromedp.Sleep(time.Second*5),
chromedp.MouseClickXY(1075, 33),
chromedp.Sleep(time.Second*5),
// A LOT MORE CLICKS AND KEY PRESSES GOING ON
chromedp.MouseClickXY(850, 61),
chromedp.Sleep(time.Second*10),
// end
chromedp.Stop(),
)
if err != nil {
fmt.Println(err)
}
I added a "debug" line and now I see tons and tons of code (HTML I guess) output in my console but I still cannot figure out where it goes wrong in all honesty.