google-chromegotestingchromedp

How to use Chrome headless with chromedp?


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?


Solution

  • 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)
    }