From 0b1c2162e3eacee8ed8882a0ddc4c451a21c56e5 Mon Sep 17 00:00:00 2001 From: Aubermean Date: Thu, 22 Feb 2024 16:50:18 +0100 Subject: [PATCH] refactor handling to not override ws_url from /json/version, and stop stripping url/ws_url query params --- lib/ferrum/browser/process.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/ferrum/browser/process.rb b/lib/ferrum/browser/process.rb index 006f975a..2a754443 100644 --- a/lib/ferrum/browser/process.rb +++ b/lib/ferrum/browser/process.rb @@ -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 @@ -187,10 +185,11 @@ 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" @@ -198,7 +197,7 @@ def parse_json_version(url) 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"]