Skip to content

Commit

Permalink
refactor handling to not override ws_url from /json/version, and stop…
Browse files Browse the repository at this point in the history
… stripping url/ws_url query params
  • Loading branch information
Aubermean authored and Aubermean committed Feb 22, 2024
1 parent 40c34ab commit 0b1c216
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/ferrum/browser/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ def initialize(options)

if options.ws_url
response = parse_json_version(options.ws_url)
self.ws_url = response&.[]("webSocketDebuggerUrl") || options.ws_url
self.ws_url = options.ws_url
return
end

if options.url
elsif options.url
response = parse_json_version(options.url)
self.ws_url = response&.[]("webSocketDebuggerUrl")
return
Expand Down Expand Up @@ -187,18 +185,19 @@ def close_io(*ios)
end

def parse_json_version(url)
url = URI.join(url, "/json/version")
uri = Addressable::URI.parse(url)
uri.path = "/json/version"

if %w[wss ws].include?(url.scheme)
url.scheme = case url.scheme
if %w[wss ws].include?(uri.scheme)
uri.scheme = case uri.scheme
when "ws"
"http"
when "wss"
"https"
end
end

response = JSON.parse(::Net::HTTP.get(URI(url.to_s)))
response = JSON.parse(::Net::HTTP.get(URI(uri.to_s)))

@v8_version = response["V8-Version"]
@browser_version = response["Browser"]
Expand Down

0 comments on commit 0b1c216

Please sign in to comment.