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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃悰 Bug]: [Ruby][C#] Exception when using wss protocol in se:cdp #10017

Closed
shashikdm opened this issue Nov 8, 2021 · 5 comments
Closed

Comments

@shashikdm
Copy link

shashikdm commented Nov 8, 2021

What happened?

I'm using a WebSocket proxy between Selenium Jar and client script for the BiDi connection. When I use ws protocol, i.e. "se:cdp": "ws://<proxy>/session/<sessionId>/se/cdp", the example script works as expected. However, if I use wss protocol, i.e. "se:cdp": "wss://<proxy>/session/<sessionId>/se/cdp", I get a runtime exception. This happens with ruby and C# client only. It works fine Java client.

How can we reproduce the issue?

require 'selenium-webdriver'

def run_session(caps)
  driver = Selenium::WebDriver.for(:remote,
  :url => "<jar_url>",
  :capabilities => caps)
  begin
    driver.get 'http://www.google.com'
    logs = []
    driver.on_log_event(:console) do |event|
      logs.push(event)
      puts logs.length
    end
    driver.execute_script('console.log("here")')
  ensure
    driver.quit
  end
end

caps = Selenium::WebDriver::Remote::Capabilities.new
caps['browserName'] = 'chrome'

run_session(caps)

Relevant log output

Traceback (most recent call last):
        9: from cdp_commands.rb:40:in `<main>'
        8: from cdp_commands.rb:11:in `run_session'
        7: from /Users/shashikantkadam/.rvm/gems/ruby-2.7.0/gems/selenium-webdriver-4.0.3/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb:66:in `on_log_event'
        6: from /Users/shashikantkadam/.rvm/gems/ruby-2.7.0/gems/selenium-webdriver-4.0.3/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb:36:in `devtools'
        5: from /Users/shashikantkadam/.rvm/gems/ruby-2.7.0/gems/selenium-webdriver-4.0.3/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb:36:in `new'
        4: from /Users/shashikantkadam/.rvm/gems/ruby-2.7.0/gems/selenium-webdriver-4.0.3/lib/selenium/webdriver/devtools.rb:45:in `initialize'
        3: from /Users/shashikantkadam/.rvm/gems/ruby-2.7.0/gems/selenium-webdriver-4.0.3/lib/selenium/webdriver/devtools.rb:124:in `start_session'
        2: from /Users/shashikantkadam/.rvm/gems/ruby-2.7.0/gems/selenium-devtools-0.94.0/lib/selenium/devtools/v94/target.rb:109:in `get_targets'
        1: from /Users/shashikantkadam/.rvm/gems/ruby-2.7.0/gems/selenium-webdriver-4.0.3/lib/selenium/webdriver/devtools.rb:68:in `send_cmd'
/Users/shashikantkadam/.rvm/gems/ruby-2.7.0/gems/selenium-webdriver-4.0.3/lib/selenium/webdriver/common/wait.rb:73:in `until': timed out after 30 seconds (Selenium::WebDriver::Error::TimeoutError)

Operating System

macOS Monterey

Selenium version

Ruby 4.0.3

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

Chrome 94

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

ChromeDriver 94.0.4606.61

Are you using Selenium Grid?

4.0.0-rc-1

@github-actions
Copy link

github-actions bot commented Nov 8, 2021

@shashikdm, 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.

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

Thank you!

@shashikdm
Copy link
Author

After some digging around ruby WebSockets, I found that it shows the timeout behaviour when connecting with any wss WebSocket endpoint. I wrote this script that performs initial steps in devtools.rb.

require 'websocket'
require 'socket'

protocol = "wss"
host = "hidden-earth-77678.herokuapp.com"
port = 443
path = "/"
socket = TCPSocket.new(host, port)
ws_url = "#{protocol}://#{host}:#{port}#{path}"
ws = WebSocket::Handshake::Client.new(url: ws_url)
socket.print(ws.to_s)
ws << socket.readpartial(1024)

puts ws.finished?
puts ws.valid?

Above script gets stuck at ws << socket.readpartial(1024) and if you change the protocol to wss and port to 80 the above script works as expected and gives output:

true
true

Please note that the host in above script (hidden-earth-77678.herokuapp.com) is a simple WebSocket server in node js explained here: https://devcenter.heroku.com/articles/node-websockets#option-1-websocket.

@shashikdm shashikdm changed the title [馃悰 Bug]: [Ruby] Exception when using wss protocol in se:cdp [馃悰 Bug]: [Ruby][C#] Exception when using wss protocol in se:cdp Nov 8, 2021
@shashikdm
Copy link
Author

Observed same behaviour with C# client library.
Exception:

OpenQA.Selenium.WebDriverException : Unexpected error creating WebSocket DevTools session.
  ----> System.Net.Http.HttpRequestException : nodename nor servname provided, or not known (wss:80)
  ----> System.Net.Sockets.SocketException : nodename nor servname provided, or not known

Stacktrace:

   at OpenQA.Selenium.Remote.RemoteWebDriver.GetDevToolsSession(Int32 protocolVersion)
   at OpenQA.Selenium.Remote.RemoteWebDriver.GetDevToolsSession()
   at SeleniumCsharp.Tests.Test1() in /Users/shashikantkadam/Projects/SeleniumCsharp/SeleniumCsharp/UnitTest1.cs:line 37
--HttpRequestException
   at System.Net.Http.ConnectHelper.ConnectAsync(Func`3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.GetStringAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
   at OpenQA.Selenium.DevTools.DevToolsSession.InitializeProtocol(Int32 requestedProtocolVersion)
   at OpenQA.Selenium.DevTools.DevToolsSession.StartSession(Int32 requestedProtocolVersion)
   at OpenQA.Selenium.Remote.RemoteWebDriver.GetDevToolsSession(Int32 protocolVersion)
--SocketException
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|283_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.DefaultConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellationToken)
   at System.Net.Http.ConnectHelper.ConnectAsync(Func`3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken)

@titusfortner
Copy link
Member

This should be fixed in 4.1, please let us know if it is not.

@github-actions
Copy link

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 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants