nightwatch.js cannot run chrome in headless mode

Viewed 4446

I cannot get it to run without it opening a visible browser window. I tried both with "headless" and "--headless" arguments

Note: I am NOT using Selenium.

Acording to this page headless mode is supported in MacOSX since version 60. I'm running version 61

https://developers.google.com/web/updates/2017/04/headless-chrome

Here's my configuration:

"chrome" : { "desiredCapabilities": { "javascriptEnabled": true, "acceptSslCerts": true, "browserName": "chrome", "chromeOptions" : { "args" : ["--headless"], "binary": "google-chrome" } } },

4 Answers

I came across the same issue earlier and the solution was to add the following args as I don't want a sandbox neither need the gpu.

"args" : ["headless", "no-sandbox", "disable-gpu"]

"chrome" : {
  "desiredCapabilities": {
    "javascriptEnabled": true,
    "acceptSslCerts": true,
    "browserName": "chrome",
    "chromeOptions" : {
      "args" : ["headless", "no-sandbox", "disable-gpu"]
    }
  }
}

If you are on linux please try this, it works perfectly for me :

            "desiredCapabilities": {
            "browserName": "chrome",
            "javascriptEnabled": true,
            "acceptSslCerts": true,
            "chromeOptions": {
                "args": [
                    "headless", "disable-gpu"
                 ],
                 "binary": "/usr/bin/google-chrome"
              }
        }

If you are on Mac, replace your binary path, eg /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

You are missing the --disable-gpu

As the url you provided mentions :

--disable-gpu \ # Temporarily needed for now.

which means you need it to use headless mode at the moment, it may not required in future version.

I had some problem with headless mode recently. The elements can not be found. Then I debug and found all the failed cases using SSL certification URL. Then I added one option acceptInsecureCerts, it works at last. Just FYI.

nightwatch.json:

...
        "desiredCapabilities": {
          "browserName": "chrome",
          "acceptSslCerts": true,
          "acceptInsecureCerts": true,
          "chromeOptions" : {
            "args": [
              "headless",
              "no-sandbox",
              "disable-gpu",
              "ignore-certificate-errors"
            ],
            "binary" : "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
          }
        },
Related