Blog
Screenshot rendering
min read

How to take website screenshots with Ruby

Take website screenshots with Ruby using Watir, Selenium, or Puppeteer, or simplify with Screenshot API as a service. Learn pros, cons, and full Ruby examples.

Capturing website screenshots from a Ruby application can be surprisingly complex. From managing headless browsers to handling rendering issues across platforms, developers often face tooling challenges, performance trade-offs, and infrastructure headaches.

This guide explores several ways to take screenshots with Ruby: using Watir, Selenium, and Puppeteer. Then we’ll show a simpler alternative using ScreenshotMAX,an API-first screenshot service built for developers who want results without running browsers themselves.

Watir for website screenshots in Ruby

Watir (Web Application Testing In Ruby) is a Ruby library built on top of Selenium WebDriver. Originally designed for automating browser testing, Watir simplifies web navigation and interaction using a Ruby-friendly syntax. It has been around since 2003 and continues to serve Rubyists needing automation or scraping tools.

Watir supports major browsers like Chrome, Firefox, and Edge via Selenium and integrates easily into Ruby applications or test suites.

Installation


gem install watir

You’ll also need Chrome and Chromedriver installed on your system.

Example code


require 'watir'

browser = Watir::Browser.new(:chrome, headless: true)
browser.goto("https://example.com")
browser.screenshot.save("screenshot.png")
browser.close

Pros and cons

Watir is great for Ruby developers who want a simple, readable interface over Selenium. It’s ideal for scripting and small-scale automation. But since it relies on Selenium and local browser drivers, setup can become tedious in CI environments or servers without a GUI. Performance is also limited by the need to boot full browsers.

Selenium for website screenshots in Ruby

Selenium is one of the oldest and most mature browser automation tools, started in 2004. It provides bindings in many languages, including Ruby, and allows fine control over real browsers through the WebDriver protocol. In Ruby, it’s used both directly or via wrappers like Watir or Capybara.

Selenium supports major browsers and works well when precise interaction with web content is required.

Installation


gem install selenium-webdriver

You’ll also need Chrome and Chromedriver installed.

Example code


require 'selenium-webdriver'

options = Selenium::WebDriver::Chrome::Options.new(args: ['headless'])
driver = Selenium::WebDriver.for(:chrome, options: options)
driver.navigate.to "https://example.com"
driver.save_screenshot("screenshot.png")
driver.quit

Pros and cons

Selenium offers powerful, low-level control and works reliably across browsers. However, it’s more verbose than Watir and can be tricky to configure. Managing WebDriver versions and dealing with flaky rendering on headless mode can be time-consuming. It’s more suited to testing frameworks than quick screenshot jobs.

Puppeteer with Ruby (via Puppeteer-ruby or CLI)

Puppeteer was created by the Google Chrome team as a Node.js library to control Chrome or Chromium. While it’s JavaScript-first, some Ruby developers use puppeteer-ruby wrappers or shell out to Puppeteer CLI to benefit from its fast, modern API for rendering web pages.

Using Puppeteer in Ruby is less direct, but still possible through gems like puppeteer-ruby or system calls.

Installation

gem install puppeteer-ruby

You also need Node.js and Chromium installed.


require 'puppeteer'

Puppeteer.launch(headless: true) do |browser|
  page = browser.new_page
  page.goto('https://example.com')
  page.screenshot(path: 'screenshot.png')
end

Pros and Cons

Puppeteer offers great performance and modern rendering capabilities. It handles dynamic content better than Selenium. However, using it in Ruby requires extra dependencies and feels less native. For production, you’ll often face challenges running Node + Chromium cleanly from Ruby processes. Puppeteer is powerful,but slightly awkward for pure Ruby workflows.

Using screenshot API as a service for Ruby developers

If managing headless browsers feels like a heavy lift, ScreenshotMAX offers a lightweight, scalable alternative: a simple API for capturing screenshots from any programming language,including Ruby. No browsers to install. No flaky rendering. No DevOps pain.

What is ScreenshotMAX?

ScreenshotMAX is a modern screenshot and HTML-to-PDF API designed for developers. You send a URL (or HTML), get back an image or PDF. It’s production-ready, fast, and cloud-hosted,no need to manage infrastructure.

There’s no SDK required. Just use Ruby’s built-in HTTP or any HTTP client.

Ruby example


require 'net/http'
require 'uri'
require 'json'

uri = URI("https://api.screenshotmax.com/v1/screenshot")
params = {
  access_key: "YOUR_ACCESS_KEY",
  url: "https://example.com",
  full_page: true,
  format: "png"
}

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.path, { 'Content-Type' => 'application/json' })
request.body = params.to_json

response = http.request(request)

File.open("screenshot.png", "wb") do |file|
  file.write(response.body)
end

Pros and cons

ScreenshotMAX eliminates the need to manage browsers or deal with system dependencies. You get reliable screenshots from any platform, including serverless or embedded Ruby environments. It’s ideal for automation, microservices, and SaaS workflows. The trade-off is less control over the rendering engine compared to full Puppeteer or Selenium,but most users won’t need that level of customization.

Conclusion

Whether you’re testing layouts, generating thumbnails, or archiving content, Ruby gives you multiple paths for capturing website screenshots.

If you need to automate complex browser interactions or generate screenshots in tightly controlled environments, Selenium or Puppeteer offers fine-grained control. It’s ideal for one-off screenshots, local development, or workflows where you need to manipulate the DOM or wait for dynamic content.

However, if your goal is to capture hundreds or thousands of screenshots reliably, especially in a production setting, a screenshot API like ScreenshotMAX is a better choice. It handles the infrastructure, parallel processing, and scaling for you, so you don’t have to worry about memory limits, browser crashes, or queueing jobs manually. You just call the API and get your result back quickly, with consistent rendering and high availability. It’s purpose-built for bulk screenshot tasks and large workloads.

Watir is friendly and readable for Rubyists, Selenium gives you precise low-level control, and Puppeteer delivers high-quality output with some cross-language work. But when simplicity, scale, and speed matter most,ScreenshotMAX offers a streamlined, API-first approach that gets the job done in seconds, without infrastructure overhead.

Try ScreenshotMAX today and integrate high-quality screenshots into your Ruby app with ease.

Published on

Read more screenshot rendering

Get practical tips, detailed guides, trusted best practices and updates.

Start now

Take website screenshots in minutes
No browser setup, no headaches, no scaling concerns

Complete API for rendering website screenshots, HTML to PDF, animated screenshots, web page scraping, and scheduled screenshots.

No credit card required