Guides · Ruby · Net::HTTP

Take a full-page screenshot in Ruby with Net::HTTP

"full_page": true captures the whole document, not just the viewport — the render scrolls the page, waits for lazy-loaded images along the way, and returns one tall image. width sets the viewport width the page lays itself out at; height is measured, not guessed.

Below is a complete, runnable Ruby program using Net::HTTP, no third-party dependency needed. It reads your API key from the SNAPDOK_KEY environment variable — free keys take about thirty seconds and need no card.

require "json"
require "net/http"
require "uri"

uri = URI("https://snapdok.io/v1/render")

res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 90) do |http|
  req = Net::HTTP::Post.new(uri)
  req["Authorization"] = "Bearer #{ENV.fetch("SNAPDOK_KEY")}"
  req["Content-Type"] = "application/json"
  req.body = JSON.generate({
    url: "https://your-app.com/report/42",
    format: "png",
    full_page: true,
    width: 1280,
})
  http.request(req)
end

raise "snapdok error #{res.code}: #{res.body}" unless res.is_a?(Net::HTTPSuccess)

File.binwrite("full.png", res.body)
puts "#{res["X-Page-Height"]}  # measured document height in CSS px"

Very tall pages hit a documented cap rather than an out-of-memory surprise: images are cut off at 20,000 CSS px, and the response says so explicitly — X-Full-Page-Truncated: 1 plus X-Page-Height with the real document height. If you need everything past the cap, ask for "tile": true and the render returns a ZIP of overlapping numbered tiles instead (covered in its own guide, linked below).

Sticky headers are the classic full-page artifact — a bar designed to follow the viewport can repeat down a scrolled capture. If a page renders oddly, try "wait_until": "networkidle" first so animations and late images settle before the scroll pass.

Same endpoint, one more trick: if the page you are rendering has a form on it, adding "pdf_forms": true to a PDF render brings it back with real, fillable AcroForm fields — a PDF people can type into, not a picture of one. How that works.

Notes for Net::HTTP

Stdlib only — no gems. The traps Net::HTTP is famous for, all handled in the sample: TLS is not automatic (set use_ssl: true or you will POST in the clear to port 80 and get a redirect); the default read_timeout of 60 s is close enough to real render times that raising it is wise; and the response body is a binary-ready String, but write it with File.binwrite — plain File.write on Windows would mangle line-ending bytes in the PDF. Check is_a?(Net::HTTPSuccess): Net::HTTP never raises on HTTP error statuses.

Response headers worth reading

HeaderMeaning
X-Page-HeightFull document height in CSS px.
X-Full-Page-Truncated1 when the image stops at the 20,000 px cap.
X-Full-Page-Max-HeightThe cap itself.

Full parameter reference: the docs. Hard numbers on caps and timeouts: limits.

Related guides

Same task, other stacks

More with Ruby + Net::HTTP