Skip to content

[馃悰 Bug]: [java] Remote file download fails with "Don't serialize binary stream - it might be large" using RemoteWebDriver.builder()聽#17137

Description

@tim-burke-systemware

Description

Environment

  • Selenium: 4.40.0
  • OS: Windows 11 x64
  • Java: 21.0.10
  • Selenium client: Using RemoteWebDriver.builder()
  • Logging: org.openqa.selenium set to FINER

Description

When attempting to download a file with .downloadFile() from a Grid node using RemoteWebDriver.builder() (the "new" builder-style API), the command fails with:

org.openqa.selenium.WebDriverException: Don't serialize binary stream - it might be large

This is due to the inclusion of DumpHttpExchangeFilter in the RemoteWebDriver.builder()'s client filter chain, which logs all HTTP exchanges. When downstream code tries to log a streamed file download response, it calls contentAsString() on the binary stream, which triggers this error.

This does not occur when:

  • Using the legacy new RemoteWebDriver(URL, Capabilities) constructor

How to Reproduce

  1. Set up Selenium Grid (standalone is enough), enable se:downloads.
  2. Set logging for org.openqa.selenium to FINER or higher.
  3. Run reproducible code

Suspected Root Cause

  • DumpHttpExchangeFilter logs HTTP responses by calling Contents.string(HttpMessage), which invokes .contentAsString() on the response object.
  • If the response is a streamed binary (InputStreamContentSupplier), this throws UnsupportedOperationException("Don't serialize binary stream - it might be large").
  • The filter chain includes ErrorFilter, which swallows the exception and turns it into a 500 error, which is thrown by the response codec as a WebDriverException to the caller.

Code/Reference Links

Reproducible Code

import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.nio.file.Paths;

RemoteWebDriver driver = RemoteWebDriver.builder()
    .address(new URL("http://localhost:4444/"))
    .addAlternative(new ChromeOptions()) // or your browser options
    .build();

driver.get("https://the-internet.herokuapp.com/download/Coffee.pptx");
driver.downloadFile("Coffee.pptx", Paths.get("."));
driver.quit();

Debugging Logs

Build info: version: '4.40.0', revision: 'b3333f1'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '21.0.10'
Driver info: org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$a6W6ipHt$ByteBuddy$TTVVMAQ4
Command: [57d2b9aba360662c6a7005bfcbfd4841, downloadFile {format=application/octet-stream, name=modifiedcamfiles.zip}]
Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 145.0.7632.117, chrome: {chromedriverVersion: 145.0.7632.117 (de4e5d6e13b..., userDataDir: C:\Users\DEV~1.SER\AppData\...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:58556}, goog:loggingPrefs: {browser: ALL, driver: ALL}, goog:processID: 776, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: Windows XP, proxy: Proxy(), se:bidiEnabled: false, se:cdp: wss://192.168.20.108:4444/s..., se:cdpVersion: 145.0.7632.117, se:downloadsEnabled: true, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
Session ID: 57d2b9aba360662c6a7005bfcbfd4841
	at org.openqa.selenium.remote.ErrorCodec.decode(ErrorCodec.java:169)
	at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:142)
	at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
	at java.base/java.util.function.Function.lambda$andThen$1(Function.java:88)
	at org.openqa.selenium.remote.RemoteWebDriverBuilder.lambda$createExecutor$9(RemoteWebDriverBuilder.java:483)
	at org.openqa.selenium.remote.RemoteWebDriverBuilder.lambda$createExecutor$10(RemoteWebDriverBuilder.java:490)
	at org.openqa.selenium.remote.RemoteWebDriverBuilder.lambda$createExecutor$11(RemoteWebDriverBuilder.java:495)
	at org.openqa.selenium.remote.RemoteWebDriverBuilder.lambda$createExecutor$12(RemoteWebDriverBuilder.java:505)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
	at org.openqa.selenium.remote.RemoteWebDriver.downloadFile(RemoteWebDriver.java:774)
	at com.systemware.swuitests.components.BaseComponent.getDownload(BaseComponent.java:2297)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

B-gridEverything grid and server relatedC-javaJava BindingsI-defectSomething is not working as intendedI-regressionSomething was working but we "fixed" it

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions