From a16c7d2f9dc742e8771da4399bdc70d8663cc8d2 Mon Sep 17 00:00:00 2001 From: Justin Bishop Date: Sun, 5 Dec 2021 09:13:04 -0800 Subject: [PATCH 1/2] use scrollWidth and scrollHeight for full page screenshot saves. I noticed that the bottom of my screenshots were getting cut off...it wasn't expanding quite far enough. When I switched to `cuprite`, however, it would work and capture the entire viewport properly. I studied the difference and `cuprite` is using `scrollWidth` and `scrollHeight` at https://github.com/rubycdp/ferrum/blob/3253bf1d028945b434ffb8e3d42636342ebf15bc/lib/ferrum/page/screenshot.rb#L66 --- lib/capybara/apparition/page.rb | 2 +- spec/integration/driver_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/capybara/apparition/page.rb b/lib/capybara/apparition/page.rb index 50f24ae..ef4ffce 100644 --- a/lib/capybara/apparition/page.rb +++ b/lib/capybara/apparition/page.rb @@ -157,7 +157,7 @@ def render(options) %w[x y width height].each_with_object({}) { |key, hash| hash[key] = pos[key] } elsif options[:full] evaluate <<~JS - { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight} + { width: document.documentElement.scrollWidth, height: document.documentElement.scrollHeight} JS else evaluate <<~JS diff --git a/spec/integration/driver_spec.rb b/spec/integration/driver_spec.rb index 06861ea..873142a 100644 --- a/spec/integration/driver_spec.rb +++ b/spec/integration/driver_spec.rb @@ -169,7 +169,7 @@ def session_url(path) create_screenshot file, full: true expect(FastImage.size(file)).to eq( - @driver.evaluate_script('[document.documentElement.clientWidth, document.documentElement.clientHeight]') + @driver.evaluate_script('[document.documentElement.scrollWidth, document.documentElement.scrollHeight]') ) end @@ -203,7 +203,7 @@ def session_url(path) create_screenshot file, full: true, selector: '#penultimate' expect(FastImage.size(file)).to eq( - @driver.evaluate_script('[document.documentElement.clientWidth, document.documentElement.clientHeight]') + @driver.evaluate_script('[document.documentElement.scrollWidth, document.documentElement.scrollHeight]') ) end From 7a2aece898d4b955a612246d8e4c17250f8b6ed4 Mon Sep 17 00:00:00 2001 From: Justin Bishop Date: Tue, 14 Dec 2021 22:09:14 -0800 Subject: [PATCH 2/2] also add captureBeyondViewport which seems necessary for me --- lib/capybara/apparition/page.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/capybara/apparition/page.rb b/lib/capybara/apparition/page.rb index ef4ffce..e4607a3 100644 --- a/lib/capybara/apparition/page.rb +++ b/lib/capybara/apparition/page.rb @@ -165,6 +165,7 @@ def render(options) JS end options[:clip] = { x: 0, y: 0, scale: scale }.merge(clip_options) + options[:captureBeyondViewport] = true command('Page.captureScreenshot', **options) end['data'] end