SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.17k stars 8.11k forks source link

[🐛 Bug]: Not able to open the devtools session twice in ruby selenium #14350

Open Mohanram3012 opened 1 month ago

Mohanram3012 commented 1 month ago

What happened?

The dev tools session is opened and i'm using it for intercepting the network request and response . I'm using ruby selenium for the above . After intercepting the driver is stuck since we are capturing the request and responses. To get the value of the intercepted request we need to close the dev tools session . We tried several ways and finally driver.devtools.close is closing the session and i'm able to move further . But with the same driver instance when i try to reopen the dev tools session i'm getting IO connection closed error . Need to reopen the dev tools session

How can we reproduce the issue?

driver.intercept do |request, &continue|
            @intercepted_logs << {request: {
             method: request.method,
             url: request.url,
             post_data: request.post_data,
             headers: request.headers
           }}
           continue.call(request)
        end
        // some code 
       driver.devtools.close
       // trying to reopen the connection with the same driver
       driver.intercept

Relevant log output

IOError: closed stream
from /Users/mok/.rvm/gems/ruby-3.2.2@rubyupgrade/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/common/websocket_connection.rb:61:in `write'

Operating System

Macos

Selenium version

Selenium 4.10 seleniumdevtools 0.126

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

Chrome 126

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

chromedriver 126.0

Are you using Selenium Grid?

No

github-actions[bot] commented 1 month ago

@Mohanram3012, 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!

Mohanram3012 commented 1 month ago

The ruby version for the above issue is ruby 3.2.2

pujagani commented 1 month ago

I suspect that calling close closes the underlying websocket and hence the error. We added a check in Java, to open the websocket again if it is closed when a devtools session is created again for the same driver. Maybe that needs to be added to Ruby. Though, we are focusing to transitioning to W3C BiDi implementation, so not sure if it is the best use of resources to add this bit.

pujagani commented 1 month ago

@p0deje @titusfortner What do you think?

p0deje commented 1 month ago

You should not really close the connection manually. This is concerning to me:

After intercepting the driver is stuck since we are capturing the request and responses

Can you elaborate on the issue? As long as you properly use continue.call(...) the driver should not stuck and you should be able to inspect the request/response accordingly.

Mohanram3012 commented 1 month ago

HI @p0deje yeah the continue call is allowing the next line of code to execute and the request and responses are captured but we don't have any way to reopen the connection or reuse the driver.intercept . For a single driver instance we are not able to intercept twice . our assumption here is we need to capture and validate the request and upon continuing we need to capture and validate the response . This gets a hit when we use driver.intercept twice or using it after closing the devtools session again

p0deje commented 1 month ago

@Mohanram3012 I see what you are saying. The thing with intercept is that it won't work with 2 calls - you have to call it only once, otherwise, all sorts of weird issues like that can happen. Is there any specific reason why you need to call it twice and cannot consolidate these 2 calls within a single one?