Reputation: 5767
I'm using chromedp, which has features to focus on elements, fill in text, etc. Chrome 59 has cross-platform headless support. It allows running Chrome in a headless/server environment. To use via the DevTools remote debugging protocol, start a normal Chrome binary with the --headless command line flag (Linux-only for now):
$ google-chrome --headless --disable-gpu --remote-debugging-port=9222 https://www.google.fr
How can I tell chromedp
to send the --headless flag, along with other flags?
Upvotes: 4
Views: 10708
Reputation: 297
In the latest version of chromedp, by default the headless mode is true, if you want to change then refer the below snippet
opts := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.Flag("headless", false),
chromedp.Flag("disable-gpu", false),
chromedp.Flag("enable-automation", false),
chromedp.Flag("disable-extensions", false),
)
allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
defer cancel()
// create context
ctx, cancel := chromedp.NewContext(allocCtx, chromedp.WithLogf(log.Printf))
defer cancel()
if err := chromedp.Run(ctx,
chromedp.Navigate(`https://www.google.com/`),
); err != nil {
log.Fatal(err)
}
Upvotes: 12
Reputation: 5767
Find It. I do
c, err := cdp.New(ctxt, cdp.WithRunnerOptions(
runner.Flag("headless", true),
runner.Flag("disable-gpu", true)))
if err != nil {
log.Fatal(err)
}
Upvotes: 8