Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Cannot create DevTools session twice #11606

Closed
MakKeywa opened this issue Feb 1, 2023 · 5 comments · Fixed by #11704
Closed

[🐛 Bug]: Cannot create DevTools session twice #11606

MakKeywa opened this issue Feb 1, 2023 · 5 comments · Fixed by #11704
Labels
C-devtools BiDi or Chrome DevTools related issues C-java I-defect

Comments

@MakKeywa
Copy link

MakKeywa commented Feb 1, 2023

What happened?

Since 4.7.1 selenium version DevTools session cannot be created after DevTools session was opened and closed.
TimeoutException is thrown.

Steps to reproduce:

  1. Create DevTools session
  2. Enable Network.
  3. Close session.
  4. Try to create new session with the same driver.

How can we reproduce the issue?

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.v108.network.Network;

import java.util.Objects;
import java.util.Optional;

public class Main {

    public static void main(String[] args) {
        WebDriverManager.chromedriver().setup();
        ChromeDriver chromeDriver = null;
        try {
            chromeDriver = new ChromeDriver();
            DevTools devTools = chromeDriver.getDevTools();
            devTools.createSession();
            devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));

            devTools.clearListeners();
            devTools.close();

            devTools = chromeDriver.getDevTools();
            devTools.createSession(); // StackTrace starts here!
            devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));

            devTools.clearListeners();
            devTools.close();
        } finally {
            Objects.requireNonNull(chromeDriver).quit();
        }
    }
}

Relevant log output

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
Starting ChromeDriver 109.0.5414.74 (e7c5703604daa9cc128ccf5a5d3e993513758913-refs/branch-heads/5414@{#1172}) on port 15746
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Feb 01, 2023 11:52:10 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 109, so returning the closest version found: 108
Exception in thread "main" org.openqa.selenium.TimeoutException: java.util.concurrent.TimeoutException
Build info: version: '4.7.1', revision: 'c6795baf1a3'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.2'
Driver info: driver.version: unknown
	at org.openqa.selenium.devtools.Connection.sendAndWait(Connection.java:162)
	at org.openqa.selenium.devtools.DevTools.findTarget(DevTools.java:146)
	at org.openqa.selenium.devtools.DevTools.createSession(DevTools.java:115)
	at org.openqa.selenium.devtools.DevTools.createSession(DevTools.java:103)
	at Main.main(Main.java:24)
Caused by: java.util.concurrent.TimeoutException
	at java.base/java.util.concurrent.CompletableFuture.timedGet(CompletableFuture.java:1960)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2095)
	at org.openqa.selenium.devtools.Connection.sendAndWait(Connection.java:151)
	... 4 more

Process finished with exit code 1

Operating System

Windows 10

Selenium version

Java 4.7.1

What are the browser(s) and version(s) where you see this issue?

Chrome: 109.0.5414.120 (64-bit)

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 109.0.5414.74

Are you using Selenium Grid?

no

@github-actions
Copy link

github-actions bot commented Feb 1, 2023

@MakKeywa, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@pujagani pujagani added the C-devtools BiDi or Chrome DevTools related issues label Feb 3, 2023
@pujagani
Copy link
Contributor

pujagani commented Feb 3, 2023

4.7.1 onwards the devtools.close() method is doing the required cleanup. Earlier, it would just send a CDP command to detach the target on close but keep the websocket connection open which would not free up the resources even after closing the devtools instance. In 4.7.1, to prevent memory leaks, the underlying connection is closed which in turn closed the websocket and hence does the required cleanup and frees up the resources. Hence, once devtools instance is closed, calling methods on it produces TimeoutException since the websocket is closed.

@MakKeywa
Copy link
Author

MakKeywa commented Feb 3, 2023

If I get it right, now it is imposible to open session twice on the same driver?
Like shouldn't you recreate that socket connection if devtools.createSession() is called?

@pujagani
Copy link
Contributor

pujagani commented Feb 6, 2023

I will revisit and see if that integration is possible and what it takes. Appreciate your suggestion.

Copy link

github-actions bot commented Dec 9, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-devtools BiDi or Chrome DevTools related issues C-java I-defect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants