Skip to content

Commit bb70a10

Browse files
authored
Fix debug_url for the latest version of Chrome (#297)
1 parent 107bf85 commit bb70a10

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-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/features/driver_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,15 @@ def create_screenshot(file, *args)
16051605

16061606
expect(@session).to have_content("test_cookie")
16071607
end
1608+
1609+
it "has a working debug_url" do
1610+
session = Capybara::Session.new(:cuprite_with_inspector, TestApp)
1611+
session.visit "/cuprite/arbitrary_path/200"
1612+
1613+
expect do
1614+
URI.parse(session.driver.debug_url)
1615+
end.not_to raise_error
1616+
end
16081617
end
16091618
end
16101619
end

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

spec/spec_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
Capybara::Cuprite::Driver.new(app, options)
3131
end
3232

33+
Capybara.register_driver(:cuprite_with_inspector) do |app|
34+
Capybara::Cuprite::Driver.new(app, { inspector: true })
35+
end
36+
3337
module TestSessions
3438
Cuprite = Capybara::Session.new(:cuprite, TestApp)
3539
end

0 commit comments

Comments
 (0)