diff --git a/CHANGELOG.md b/CHANGELOG.md index 31e0fd1e..cf7989af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Correctly set mouse events buttons property [#509] - Prevent 'Hash#[]=': can't add a new key into hash during iteration [#513] - `Ferrum::Network::Exchange#finished?` and `Ferrum::Network#wait_for_idle` take into account that request can be a blob [#496] +- Safe call _body_ method (DOM) when page is empty and no html [#522] ### Removed diff --git a/lib/ferrum/frame/dom.rb b/lib/ferrum/frame/dom.rb index 4b1a9573..211cd544 100644 --- a/lib/ferrum/frame/dom.rb +++ b/lib/ferrum/frame/dom.rb @@ -92,7 +92,7 @@ def doctype # browser.body # => '... # def body - evaluate("document.documentElement.outerHTML") + evaluate("document.documentElement?.outerHTML") || "" end # diff --git a/spec/network_spec.rb b/spec/network_spec.rb index 7ad22a24..c1df9103 100644 --- a/spec/network_spec.rb +++ b/spec/network_spec.rb @@ -517,6 +517,6 @@ %r{Request to http://.*/with_js failed \(net::ERR_INTERNET_DISCONNECTED\)} ) - expect(page.at_css("body").text).to match("No internet") + expect(page.at_css("body").text).to match("") end end diff --git a/spec/unit/browser_spec.rb b/spec/unit/browser_spec.rb index 700330d5..f09112fc 100644 --- a/spec/unit/browser_spec.rb +++ b/spec/unit/browser_spec.rb @@ -19,7 +19,7 @@ def puts(*args) browser = Ferrum::Browser.new(logger: logger) browser.body file_log = File.read(file_path) - expect(file_log).to include("return document.documentElement.outerHTML") + expect(file_log).to include("return document.documentElement?.outerHTML") expect(file_log).to include("") ensure FileUtils.rm_f(file_path) @@ -32,7 +32,7 @@ def puts(*args) browser.body - expect(logger.string).to include("return document.documentElement.outerHTML") + expect(logger.string).to include("return document.documentElement?.outerHTML") expect(logger.string).to include("") ensure browser.quit