'Host header or origin header is specified and is not localhost for selenium grid

I am trying to set up a selenium grid using the latest chrome and chromedriver. I get the following error when trying to run a test

Message: OpenQA.Selenium.WebDriverException : Unexpected error. Host header or origin header is specified and is not localhost.

On the node machine, I see the chrome browser open, but then it immediately closes and I get this error:

[1557513678.682][SEVERE]: Rejecting request with host: <hub_IP_address>:4444

Has anyone had this issue using the selenium grid? I am using:

  • selenium-server-standalone-4.0.0-alpha-1.jar and
  • Chromedriver 74.0.3729.6 for windows
  • My Chrome browser was running v.74.0.3729.108
  • JDK 12.0.1.0

Here is my command for starting the hub:

java -jar selenium-server-standalone-4.0.0-alpha-1.jar -role hub -hubConfig config.json

Here is my command to start a node:

java -Dwebdriver.chrome.driver="C:\...\Browsers\ChromeDirectory\chromedriver.exe" -Dwebdriver.ie.driver="C:\...\Browsers\IEDirectory\x86\IEDriverServer.exe" -jar -Dwebdriver.edge.driver="C:\...\Browsers\Edge\MicrosoftWebDriver.exe" -jar "C:\...\selenium-server-standalone-4.0.0-alpha-1.jar" -role node -hub "http://<hub_IP_address>:4444/grid/register/" -nodeConfig "C:\...\config.json"

I tried using a "host" property in the config.jsons. I tried putting the actual IP address and just localhost. But the hub and the node are obviously different machines, so putting localhost makes it so they can't connect. But when I dont have localhost, it says it needs to be specified as localhost? I'm so confused!! What is supposed to go in the host property?

I have seen people talk about a loopback property for protractor but I am not using protractor. I tried putting "loopback":true into both my node and hub config.json files but it doesn't seem to make a difference.

UPDATE: I was able to get the grid to run successfully using the 4.0 alpha jar for the hub, and the old 3.8 jars for the nodes. All Still on Java 8. Kind of interesting.



Solution 1:[1]

You can try to add these switches: --whitelisted-ips --allowed-origins=''*

Try to run your node with command:

java -Dwebdriver.chrome.driver="C:\...\Browsers\ChromeDirectory\chromedriver.exe --whitelisted-ips --allowed-origins='*'" -Dwebdriver.ie.driver="C:\...\Browsers\IEDirectory\x86\IEDriverServer.exe" -jar -Dwebdriver.edge.driver="C:\...\Browsers\Edge\MicrosoftWebDriver.exe" -jar "C:\...\selenium-server-standalone-4.0.0-alpha-1.jar" -role node -hub "http://<hub_IP_address>:4444/grid/register/" -nodeConfig "C:\...\config.json"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 emksk