8

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" } } },

J. Araujo
  • 89
  • 1
  • 8

4 Answers4

7

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"]
    }
  }
}
PaulMest
  • 12,925
  • 7
  • 53
  • 50
Sylvester Loreto
  • 404
  • 6
  • 18
  • Thanks I will try that exact code when I have some time but I vaguely remember trying several combinations of these same arguments and none of the combinations worked for me at the time – J. Araujo Nov 28 '17 at 19:58
2

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

Bao Tran
  • 618
  • 4
  • 15
  • I tried with the binary paths such as */Applications/Google Chrome.app* and */Applications/Google Chrome.app/Contents/MacOS/Google Chrome*. Same thing. It can run the browser fine but it always opens a visible window, which is not what I expect – J. Araujo Oct 09 '17 at 14:23
  • Please make sure the path is correct and also remember the backslash in `/Google\ Chrome` . – Bao Tran Oct 10 '17 at 11:36
  • How can I be sure I have the correct binary path? Adding the \ did not help. Are you really testing it in MacOSX? Do you have a working nightwatch.json for MacOSX that you can share so I can try it? – J. Araujo Oct 10 '17 at 14:44
  • yes, i am using it now. You can check by copy and paste the path in terminal then if chrome open => the path is good. – Bao Tran Oct 12 '17 at 06:42
1

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.

Ray
  • 1,539
  • 1
  • 14
  • 27
  • I had actually tried with that argument before, and just tried it again both with and without the dashes. At least in my machine it doesn't fix it. – J. Araujo Oct 06 '17 at 14:15
0

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"
          }
        },
Rishav
  • 3,818
  • 1
  • 31
  • 49
Kathy
  • 9
  • 1