Closed kyledrake closed 1 year ago
Possible workaround is to use clip
:
require 'puppeteer'
Puppeteer.launch(headless: true) do |browser|
page = browser.pages.first || browser.new_page
page.viewport = Puppeteer::Viewport.new(width: 1280, height: 800)
page.goto("https://github.com/YusukeIwaki")
page.screenshot(path: "1.capture_a_site.png", clip: {x: 0, y: 0, width: 1280, height: 800})
end
Current version of puppeteer-ruby issues a CDP command Page.captureScreenshot
with an option captureBeyondViewport: true
unexpectedly.
$ DEBUG=1 bundle exec ruby capture.rb | grep capture
D, [2023-01-19T01:43:47.390049 #88713] DEBUG -- : SEND >> {"sessionId":"F2B6134C8553CF72D74712F9E7B32669","method":"Page.captureScreenshot","params":{"format":"png","captureBeyondViewport":true},"id":18}
Older version didn't.
$ DEBUG=1 bundle exec ruby capture.rb | grep capture
D, [2023-01-19T01:43:10.974871 #88618] DEBUG -- : SEND >> {"sessionId":"92E2BEA571CD5774E4045ADDB145E4BC","method":"Page.captureScreenshot","params":{"format":"png"},"id":17}
@kyledrake Sorry for inconvenience, puppeteer-ruby 0.45.1 would fix this issue. Please try it.
Expected behavior is image that's cropped to the browser viewport, instead it returns a full page screenshot: