@@ -13,7 +13,7 @@ module UI_CDP
1313 SHOW_PROTOCOL = ENV [ 'RUBY_DEBUG_CDP_SHOW_PROTOCOL' ] == '1'
1414
1515 class << self
16- def setup_chrome addr
16+ def setup_chrome addr , uuid
1717 return if CONFIG [ :chrome_path ] == ''
1818
1919 port , path , pid = run_new_chrome
@@ -51,7 +51,7 @@ def setup_chrome addr
5151 ws_client . send sessionId : s_id , id : 5 ,
5252 method : 'Page.navigate' ,
5353 params : {
54- url : "devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&ws=#{ addr } /#{ SecureRandom . uuid } " ,
54+ url : "devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&ws=#{ addr } /#{ uuid } " ,
5555 frameId : f_id
5656 }
5757 when res [ 'method' ] == 'Page.loadEventFired'
@@ -102,6 +102,49 @@ def run_new_chrome
102102 end
103103 end
104104
105+ def send_chrome_response req
106+ @repl = false
107+ case req
108+ when /^GET\s \/ json\/ version\s HTTP\/ 1.1/
109+ body = {
110+ Browser : "ruby/v#{ RUBY_VERSION } " ,
111+ 'Protocol-Version' : "1.1"
112+ }
113+ send_http_res body
114+ raise UI_ServerBase ::RetryConnection
115+
116+ when /^GET\s \/ json\s HTTP\/ 1.1/
117+ @uuid = @uuid || SecureRandom . uuid
118+ addr = @local_addr . inspect_sockaddr
119+ body = [ {
120+ description : "ruby instance" ,
121+ devtoolsFrontendUrl : "devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=#{ addr } /#{ @uuid } " ,
122+ id : @uuid ,
123+ title : $0,
124+ type : "node" ,
125+ url : "file://#{ File . absolute_path ( $0) } " ,
126+ webSocketDebuggerUrl : "ws://#{ addr } /#{ @uuid } "
127+ } ]
128+ send_http_res body
129+ raise UI_ServerBase ::RetryConnection
130+
131+ when /^GET\s \/ (\w {8}-\w {4}-\w {4}-\w {4}-\w {12})\s HTTP\/ 1.1/
132+ raise 'Incorrect uuid' unless $1 == @uuid
133+
134+ @need_pause_at_first = false
135+ CONFIG . set_config no_color : true
136+
137+ @ws_server = WebSocketServer . new ( @sock )
138+ @ws_server . handshake
139+ end
140+ end
141+
142+ def send_http_res body
143+ json = JSON . generate body
144+ header = "HTTP/1.0 200 OK\r \n Content-Type: application/json; charset=UTF-8\r \n Cache-Control: no-cache\r \n Content-Length: #{ json . bytesize } \r \n \r \n "
145+ @sock . puts "#{ header } #{ json } "
146+ end
147+
105148 module WebSocketUtils
106149 class Frame
107150 attr_reader :b
0 commit comments