@@ -62,13 +62,11 @@ def self.directory_remover(path)
6262 def initialize ( options )
6363 @pid = @xvfb = @user_data_dir = nil
6464
65- if options . ws_url
66- response = parse_json_version ( options . ws_url )
67- self . ws_url = options . ws_url
68- return
69- elsif options . url
70- response = parse_json_version ( options . url )
71- self . ws_url = response &.[]( "webSocketDebuggerUrl" )
65+ if options . ws_url || options . url
66+ # `:ws_url` option is higher priority than `:url`, parse versions
67+ # and use it as a ws_url, otherwise use what has been parsed.
68+ response = parse_json_version ( options . ws_url || options . url )
69+ self . ws_url = options . ws_url || response &.[]( "webSocketDebuggerUrl" )
7270 return
7371 end
7472
@@ -185,19 +183,18 @@ def close_io(*ios)
185183 end
186184
187185 def parse_json_version ( url )
188- uri = Addressable ::URI . parse ( url )
189- uri . path = "/json/version"
186+ url = URI . join ( url , "/json/version" )
190187
191- if %w[ wss ws ] . include? ( uri . scheme )
192- uri . scheme = case uri . scheme
188+ if %w[ wss ws ] . include? ( url . scheme )
189+ url . scheme = case url . scheme
193190 when "ws"
194191 "http"
195192 when "wss"
196193 "https"
197194 end
198195 end
199196
200- response = JSON . parse ( ::Net ::HTTP . get ( URI ( uri . to_s ) ) )
197+ response = JSON . parse ( ::Net ::HTTP . get ( URI ( url . to_s ) ) )
201198
202199 @v8_version = response [ "V8-Version" ]
203200 @browser_version = response [ "Browser" ]
@@ -206,7 +203,7 @@ def parse_json_version(url)
206203 @protocol_version = response [ "Protocol-Version" ]
207204
208205 response
209- rescue StandardError
206+ rescue JSON :: ParserError
210207 # nop
211208 end
212209 end
0 commit comments