What happened?
I'm using Firefox 106 with selenium-firefox-driver:4.5.0 for Java and geckodriver 0.32.0 (via Selenide 6.9.0)
Selenium GeckoDriverService launches geckodriver and when starting a new browser session it calls PUT http://localhost:<port>/session
However, since the --allow-hosts localhost flag is not provided when starting geckodriver, requests to geckodriver always return 500 Invalid Host Header
Source of geckodriver arguments:
|
@Override |
|
protected List<String> createArgs() { |
|
List<String> args = new ArrayList<>(); |
|
int wsPort = PortProber.findFreePort(); |
|
args.add(String.format("--port=%d", getPort())); |
|
args.add(String.format("--websocket-port=%d", wsPort)); |
|
args.add("--allow-origins"); |
|
args.add(String.format("http://127.0.0.1:%d", wsPort)); |
|
args.add(String.format("http://localhost:%d", wsPort)); |
|
args.add(String.format("http://[::1]:%d", wsPort)); |
|
if (firefoxBinary != null) { |
|
args.add("-b"); |
|
args.add(firefoxBinary.getPath()); |
|
} else { |
|
// Read system property for Firefox binary and use those if they are set |
|
Optional<Executable> executable = |
|
Optional.ofNullable(FirefoxBinary.locateFirefoxBinaryFromSystemProperty()); |
|
executable.ifPresent(e -> { |
|
args.add("-b"); |
|
args.add(e.getPath()); |
|
}); |
|
} |
|
// If the binary stays null, GeckoDriver will be responsible for finding Firefox on the PATH or via a capability. |
|
return unmodifiableList(args); |
|
} |
Source of target url for reqeusts to geckodriver:
|
protected URL getUrl(int port) throws IOException { |
|
return new URL(String.format("http://localhost:%d", port)); |
|
} |
My suggestion would be to update GeckoDriverService to either include --allow-hosts localhost or override ::getPort(int) to http://127.0.0.1:%d.
How can we reproduce the issue?
Breaks 100% of the time with the specified versions:
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
public class Main {
public static void main(String[] args) throws Exception {
var options = new FirefoxOptions();
System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver"); // geckodriver 0.32.0
options.setBinary("/usr/bin/firefox"); // firefox 106 installed
var driver = new FirefoxDriver(options);
driver.get("https://www.stackoverflow.com");
}
}
Relevant log output
1668526366108 geckodriver INFO Listening on 127.0.0.1:55726
1668526366212 webdriver::server WARN Rejected request with Host header localhost:55726, allowed values are []
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Invalid Host header localhost:55726
Operating System
linux
Selenium version
java 4.5.0
What are the browser(s) and version(s) where you see this issue?
Firefox 106
What are the browser driver(s) and version(s) where you see this issue?
geckodriver 0.32.0
What happened?
I'm using Firefox 106 with
selenium-firefox-driver:4.5.0for Java and geckodriver 0.32.0 (via Selenide 6.9.0)Selenium
GeckoDriverServicelaunchesgeckodriverand when starting a new browser session it callsPUT http://localhost:<port>/sessionHowever, since the
--allow-hosts localhostflag is not provided when startinggeckodriver, requests to geckodriver always return500 Invalid Host HeaderSource of
geckodriverarguments:selenium/java/src/org/openqa/selenium/firefox/GeckoDriverService.java
Lines 187 to 211 in 7fdaf21
Source of target url for reqeusts to
geckodriver:selenium/java/src/org/openqa/selenium/remote/service/DriverService.java
Lines 172 to 174 in 7fdaf21
My suggestion would be to update
GeckoDriverServiceto either include--allow-hosts localhostor override::getPort(int)tohttp://127.0.0.1:%d.How can we reproduce the issue?
Breaks 100% of the time with the specified versions:
Relevant log output
Operating System
linux
Selenium version
java 4.5.0
What are the browser(s) and version(s) where you see this issue?
Firefox 106
What are the browser driver(s) and version(s) where you see this issue?
geckodriver 0.32.0