diff --git a/lib/capybara/poltergeist/client/compiled/web_page.js b/lib/capybara/poltergeist/client/compiled/web_page.js index 8b7198d..d3f072f 100644 --- a/lib/capybara/poltergeist/client/compiled/web_page.js +++ b/lib/capybara/poltergeist/client/compiled/web_page.js @@ -392,12 +392,12 @@ Poltergeist.WebPage = (function() { }; WebPage.prototype.currentUrl = function() { - return this["native"]().url; + return this["native"]().url || this.runCommand('frameUrl'); }; WebPage.prototype.frameUrl = function() { if (phantom.version.major > 2 || (phantom.version.major === 2 && phantom.version.minor >= 1)) { - return this["native"]().frameUrl; + return this["native"]().frameUrl || this.runCommand('frameUrl'); } else { return this.runCommand('frameUrl'); } diff --git a/lib/capybara/poltergeist/client/web_page.coffee b/lib/capybara/poltergeist/client/web_page.coffee index 64d0243..45cb111 100644 --- a/lib/capybara/poltergeist/client/web_page.coffee +++ b/lib/capybara/poltergeist/client/web_page.coffee @@ -236,11 +236,13 @@ class Poltergeist.WebPage this.native().frameTitle currentUrl: -> - @native().url + # native url doesn't return anything when about:blank + # in that case get the frame url which will be main window + @native().url || @runCommand('frameUrl') frameUrl: -> if phantom.version.major > 2 || (phantom.version.major == 2 && phantom.version.minor >= 1) - @native().frameUrl + @native().frameUrl || @runCommand('frameUrl') else @runCommand('frameUrl') diff --git a/spec/integration/session_spec.rb b/spec/integration/session_spec.rb index f360110..fde19d4 100644 --- a/spec/integration/session_spec.rb +++ b/spec/integration/session_spec.rb @@ -579,6 +579,11 @@ describe Capybara::Session do @session.visit "/poltergeist/arbitrary_path/200/foo?a=%20%5B%5D%3A%2F%2B%26%3D" expect(request_uri).to eq('/poltergeist/arbitrary_path/200/foo?a=%20%5B%5D%3A%2F%2B%26%3D') end + + it 'returns about:blank when on about:blank' do + @session.visit 'about:blank' + expect(@session.current_url).to eq('about:blank') + end end context 'dragging support' do