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

Better handling of ws_url, and avoid stripping query params from url #447

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading