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

[rb] Add secure websocket support for Devtools #10023

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions rb/lib/selenium/webdriver/devtools.rb
Expand Up @@ -45,7 +45,7 @@ def initialize(url:)
def close
@callback_threads.list.each(&:exit)
@socket_thread.exit
socket.close
@socket.close
end

def callbacks
Expand All @@ -60,7 +60,7 @@ def send_cmd(method, **params)
WebDriver.logger.debug "DevTools -> #{data}"

out_frame = WebSocket::Frame::Outgoing::Client.new(version: ws.version, data: data, type: 'text')
socket.write(out_frame.to_s)
@socket.write(out_frame.to_s)

message = wait.until do
@messages.find { |m| m['id'] == id }
Expand Down Expand Up @@ -92,17 +92,17 @@ def respond_to_missing?(method, *_args)
private

def process_handshake
socket.print(ws.to_s)
ws << socket.readpartial(1024)
create_socket.print(ws.to_s)
ws << @socket.readpartial(1024)
end

def attach_socket_listener
Thread.new do
Thread.current.abort_on_exception = true
Thread.current.report_on_exception = false

until socket.eof?
incoming_frame << socket.readpartial(1024)
until @socket.eof?
incoming_frame << @socket.readpartial(1024)

while (frame = incoming_frame.next)
message = process_frame(frame)
Expand Down Expand Up @@ -160,8 +160,17 @@ def wait
@wait ||= Wait.new(timeout: RESPONSE_WAIT_TIMEOUT, interval: RESPONSE_WAIT_INTERVAL)
end

def socket
@socket ||= TCPSocket.new(ws.host, ws.port)
def create_socket
uri = URI.parse(@url)
if(uri.scheme == 'wss')
tcp_socket= TCPSocket.new(ws.host, ws.port)
ssl_context = OpenSSL::SSL::SSLContext.new()
@socket ||= OpenSSL::SSL::SSLSocket.new(tcp_socket, ssl_context)
@socket.sync_close = true
@socket.connect
else
@socket = TCPSocket.new(ws.host, ws.port)
end
end

def ws
Expand Down