Skip to content

Commit 486a64a

Browse files
authored
Fix: Safe call body method (DOM) when page is empty (#522)
1 parent 3e50daa commit 486a64a

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- Correctly set mouse events buttons property [#509]
2222
- Prevent 'Hash#[]=': can't add a new key into hash during iteration [#513]
2323
- `Ferrum::Network::Exchange#finished?` and `Ferrum::Network#wait_for_idle` take into account that request can be a blob [#496]
24+
- Safe call _body_ method (DOM) when page is empty and no html [#522]
2425

2526
### Removed
2627

lib/ferrum/frame/dom.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def doctype
9292
# browser.body # => '<html itemscope="" itemtype="http://schema.org/WebPage" lang="ru"><head>...
9393
#
9494
def body
95-
evaluate("document.documentElement.outerHTML")
95+
evaluate("document.documentElement?.outerHTML") || ""
9696
end
9797

9898
#

spec/network_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,6 @@
517517
%r{Request to http://.*/with_js failed \(net::ERR_INTERNET_DISCONNECTED\)}
518518
)
519519

520-
expect(page.at_css("body").text).to match("No internet")
520+
expect(page.at_css("body").text).to match("")
521521
end
522522
end

spec/unit/browser_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def puts(*args)
1919
browser = Ferrum::Browser.new(logger: logger)
2020
browser.body
2121
file_log = File.read(file_path)
22-
expect(file_log).to include("return document.documentElement.outerHTML")
22+
expect(file_log).to include("return document.documentElement?.outerHTML")
2323
expect(file_log).to include("<html><head></head><body></body></html>")
2424
ensure
2525
FileUtils.rm_f(file_path)
@@ -32,7 +32,7 @@ def puts(*args)
3232

3333
browser.body
3434

35-
expect(logger.string).to include("return document.documentElement.outerHTML")
35+
expect(logger.string).to include("return document.documentElement?.outerHTML")
3636
expect(logger.string).to include("<html><head></head><body></body></html>")
3737
ensure
3838
browser.quit

0 commit comments

Comments
 (0)