Skip to content

Commit

Permalink
Fix: Safe call body method (DOM) when page is empty (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoid authored Feb 20, 2025
1 parent 3e50daa commit 486a64a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/ferrum/frame/dom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def doctype
# browser.body # => '<html itemscope="" itemtype="http://schema.org/WebPage" lang="ru"><head>...
#
def body
evaluate("document.documentElement.outerHTML")
evaluate("document.documentElement?.outerHTML") || ""
end

#
Expand Down
2 changes: 1 addition & 1 deletion spec/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions spec/unit/browser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("<html><head></head><body></body></html>")
ensure
FileUtils.rm_f(file_path)
Expand All @@ -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("<html><head></head><body></body></html>")
ensure
browser.quit
Expand Down

0 comments on commit 486a64a

Please sign in to comment.