Selenium 4's NetworkInterceptor and ChromeDriver 109: DevToolsException Issue

314 Views Asked by At

I'm trying to use some example code at the beginning of exploring intercepting network requests in Selenium 4.

Selenium version: 4.3.0 ChromeDriver version: 109.0.5414.74

Code sample:

ChromeDriver driver = new ChromeDriver();

NetworkInterceptor interceptor = new NetworkInterceptor(
    driver, Route.matching(req -> true)
        .to(() -> req -> new HttpResponse()
            .setStatus(200)
            .addHeader("Content-Type", MediaType.HTML_UTF_8.toString())
            .setContent(utf8String("Creamy, delicious cheese!"))));

    driver.get("https://example-sausages-site.com");

    String source = driver.getPageSource();

    assertThat(source).contains("delicious cheese!");

This error occurs when trying to use NetworkInterceptor:

org.openqa.selenium.devtools.DevToolsException: You are using a no-op implementation of
the CDP. The most likely reason for this is that Selenium was unable to find an 
implementation of the CDP protocol that matches your browser. Please be sure to include an 
implementation on the classpath, possibly by adding a new (maven) dependency of 
`org.seleniumhq.selenium:selenium-devtools-vNN:4.3.0` where `NN` matches the major version of 
the browser you're using.
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: 'frank-ulyana-xfce', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', 
os.version: '5.15.0-58-generic', java.version: '11.0.17'
Driver info: DevTools Connection 

I'm thinking this is a version issue? The version of NetworkInterceptor doesn't support ChromeDriver 109?

If so, can I just download version 108 and just instantiate that directly, while waiting for a version that supports 109?

I'm using Maven, so all versions and dependencies are managed there.

1

There are 1 best solutions below

1
On

According to the 4.3.0 CHANGELOG, this version supports Chrome DevTools Protocol (CDP) versions 85, 101, 102, and 103. However, you are currently using CDP version 109 with your ChromeDriver.

This version discrepancy in the error message is due to the Selenium version not supporting the CDP version included in your ChromeDriver. You need to ensure your versions of Selenium and ChromeDriver (and its underlying CDP version) are compatible.

You should keep an eye on the CHANGELOG to verify the compatibility of future Selenium and CDP versions. As you are using Maven, this should help you manage and align the versions of your dependencies more effectively.

In order to resolve this issue, you would need to use Selenium 4.8.x variant, as these versions are confirmed to support CDP version 109, according to the Selenium CHANGELOG.