3

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?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
LeMoussel
  • 5,290
  • 12
  • 69
  • 122

2 Answers2

11

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)
}
Nagendran
  • 277
  • 2
  • 7
8

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)
}
LeMoussel
  • 5,290
  • 12
  • 69
  • 122