Open
Description
What happened?
I am using following setup of chrome driver:
import io.github.bonigarcia.wdm.WebDriverManager;
public ChromeDriver configureChromeDriver() {
WebDriverManager.chromedriver().setup();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--disable-extensions");
ChromeDriver chromeDriver = (ChromeDriver)
WebDriverManager.chromedriver().capabilities(chromeOptions).create();
Headers headers = new Headers(getCustomHeaders());
DevTools devTools = chromeDriver.getDevTools();
devTools.createSession();
devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
// Create request patterns to intercept
List<RequestPattern> patterns = new ArrayList<>();
// Intercept HTTPS requests for specific URLs or resource types
patterns.add(new RequestPattern(
Optional.of(BASE_URI + "/*"), // URL pattern
Optional.empty(), // Resource type
Optional.empty() // Request stage (optional)
));
devTools.send(Network.setRequestInterception(patterns));
devTools.addListener(Network.requestIntercepted(), request -> {
// Check if headers should be added
if(request.getRequest().getUrl().contains(BASE_URI + "/*")){
devTools.send(Network.continueInterceptedRequest(
request.getInterceptionId(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(headers),
Optional.empty()
));
} else {
// Continue the request without modifications
devTools.send(Network.continueInterceptedRequest(
request.getInterceptionId(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty()
));
}
});
chromeDriver.manage().window().maximize();
return chromeDriver;
}
private Map<String, Object> getCustomHeaders() {
Map<String, Object> headers = new HashMap<>();
headers.put(EMAIL_KEY, EMAIL);
return headers;
}
Later I am using this configured driver in the test as follwos:
ChromeDriver driver = configureChromeDriver();
MyPage myPage = new MyPage(driver);
// Later in this part I am opening page with driver.get(myUri) and clicking through my web application.
webPage.openWebPage(BASE_URI);
Once there is a situation that browser is making call to backend as POST, PUT or PATCH there is no Content-Type header at all which is returning errors from backend. I can observe that my custom headers and many other default headers are available.
Dependencies:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.30.0</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>6.0.0</version>
</dependency>
I am attaching request headers from manual tests in Chrome browser as well request headers which are provided from driver managed chrome browser
WebDriver managed Chrome headers:
How can we reproduce the issue?
Please use WebDriver configuration as mentioned in above code snippet and run any page. Once test is running and you see place on webpage that triggers call to backend with required content type header add Thread.sleep for some long time that you can open developer tools and click in driver managed browser the button which will trigger call to backend. In Network Section check for Request Headers and there you can see that Content-type is not being added.
Relevant log output
No exception appearing, just missing Content-type header.
Operating System
Windows10
Selenium version
Java 21
What are the browser(s) and version(s) where you see this issue?
Chrome - 134
What are the browser driver(s) and version(s) where you see this issue?
ChromeDriver 134.0.6998.165
Are you using Selenium Grid?
No