Skip to content

Commit 5137e30

Browse files
committed
Fix debug_url for latest version of chrome
it appears that devtoolsFrontendUrl returns a fully qualified URL in the latest version of Chrome, so it should be returned as-is without prepending anything to it.
1 parent 796a2f3 commit 5137e30

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/capybara/cuprite/driver.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,11 @@ def dismiss_modal(type, options = {})
379379
private
380380

381381
def build_remote_debug_url(path:)
382-
"http://#{browser.process.host}:#{browser.process.port}#{path}"
382+
uri = URI.parse(path)
383+
uri.scheme ||= "http"
384+
uri.host ||= browser.process.host
385+
uri.port ||= browser.process.port
386+
uri.to_s
383387
end
384388

385389
def default_domain

spec/lib/driver_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
end
3131

3232
describe "debug_url" do
33-
it "parses the devtools frontend url correctly" do
33+
it "parses the devtools frontend url correctly when devtoolsFrontendUrl is relative" do
3434
driver = described_class.new(nil, { port: 12_345 })
3535
driver.browser # initialize browser before stubbing Net::HTTP as it also calls it
3636
uri = instance_double(URI)
@@ -40,6 +40,19 @@
4040

4141
expect(driver.debug_url).to eq("http://127.0.0.1:12345/works")
4242
end
43+
44+
it "parses the devtools frontend url correctly when devtoolsFrontendUrl is fully qualified" do
45+
driver = described_class.new(nil, { port: 12_346 })
46+
driver.browser # initialize browser before stubbing Net::HTTP as it also calls it
47+
uri = instance_double(URI)
48+
49+
allow(driver).to receive(:URI).with("http://127.0.0.1:12346/json").and_return(uri)
50+
allow(Net::HTTP).to receive(:get).with(uri).and_return(
51+
%([{"devtoolsFrontendUrl":"https://chrome-devtools-frontend.appspot.com/serve_rev?ws=123"}])
52+
)
53+
54+
expect(driver.debug_url).to eq("https://chrome-devtools-frontend.appspot.com/serve_rev?ws=123")
55+
end
4356
end
4457

4558
private

0 commit comments

Comments
 (0)