DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
browser automation

How to Capture Webpages as PNG Images in Ruby

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To save a webpage as a PNG in Ruby, drive a browser to the page and save its rendered screenshot. For a direct Chrome or Chromium workflow, Ferrum provides a compact API:

require "ferrum"

browser = Ferrum::Browser.new
begin
  browser.go_to("https://example.com")
  browser.screenshot(path: "page.png")
ensure
  browser.quit
end

This captures the browser viewport. Use full: true for a full-document image, or selector: to capture one element. Ferrum requires Chrome or Chromium to be installed, even though it does not use Selenium, WebDriver, or ChromeDriver.

Choose a Ruby screenshot library

Pick the tool that fits the browser automation already in your application. A screenshot is an image of rendered browser content, so each route still needs a browser runtime appropriate to that tool.

Library Best fit What the cited documentation establishes
Ferrum A direct Ruby API controlling Chrome or Chromium. Controls the browser through CDP and does not depend on Selenium, WebDriver, or ChromeDriver; a Chrome or Chromium binary is required. Its screenshot API supports paths and several capture scopes.
Cuprite An existing Capybara project that wants a headless Chrome or Chromium driver. Cuprite is built on Ferrum.
Selenium A codebase already organized around WebDriver. Official Ruby documentation demonstrates browser navigation and element screenshots, and documents save_screenshot(png_path, full_page: false).
Watir An existing Watir browser-automation project. Its screenshot object can save to a path or provide PNG and Base64 data.

The available documentation does not establish a current speed ranking or a complete compatibility matrix, so there is no evidence-based universal winner. Compare fit with your test stack, browser setup, and whether you need a viewport, full page, or selected element.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall

Capture a PNG with Ferrum

Install the gem and browser

Add Ferrum to the project and install its dependencies using the current instructions for your operating system. Ferrum’s project documentation says the browser binary must be available on PATH or BROWSER_PATH, or configured with browser_path. A minimal gem installation is:

gem install ferrum

Ensure Chrome or Chromium is installed in the environment where the Ruby process will run. Installation and browser packaging vary by platform, so use Ferrum’s current setup documentation rather than assuming a browser is bundled with the gem.

Save the viewport as PNG

The basic example navigates to a URL, writes a screenshot, and closes the browser even if navigation or capture raises an error:

require "ferrum"

browser = Ferrum::Browser.new
begin
  browser.go_to("https://example.com")
  browser.screenshot(path: "page.png")
ensure
  browser.quit
end

Ferrum’s screenshot API defaults to PNG. Passing path: writes the image to disk, using binary encoding for the file write. The result is the current viewport, not automatically the entire document.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Capture the whole page or an element

Choose the capture scope explicitly. Full-page capture requests a document-sized image; selector capture targets a CSS-matched element:

# Entire document
browser.screenshot(path: "full-page.png", full: true)

# One element
browser.screenshot(path: "card.png", selector: ".product-card")

These are alternatives to a viewport screenshot, not additive options. Ferrum warns that selector: or area: is ignored if full: true is also supplied. If both selector: and area: are supplied, area: is ignored. Avoid combining modes when you expect a specific region.

Choose an output format or return image data

Ferrum documents PNG, JPEG/JPG, and WebP formats; PNG is the default. If you need the image in memory rather than a file, request Base64 or binary encoding:

png_base64 = browser.screenshot(format: "png", encoding: :base64)

Other documented controls include area: for a rectangular region, scale: to change capture scale, and background_color: to set the page background through Ferrum’s RGBA type. Check the installed version’s API documentation for accepted values and exact option shapes before adding these to production code.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Wait for the content you want to capture

A screenshot records what the browser has rendered at capture time. The page must have loaded the content you want, but a navigation completing does not necessarily mean that client-side rendering, images, or other delayed content are ready. The cited Ferrum API material does not prescribe one universally reliable wait condition. Choose a condition based on the target page rather than assuming a fixed sleep will work everywhere.

  • For a page with a known key element, wait for that element to appear before capturing.
  • For content that updates after navigation, wait for the relevant state or application-specific signal.
  • For images and lazy-loaded sections, ensure the page has rendered or scrolled the required content before taking a full-page capture.

Keep waits scoped to what matters: waiting too briefly can capture incomplete content; waiting indefinitely can hang a batch job. Set an overall job timeout in the surrounding application and handle navigation or wait failures explicitly.

Use Selenium or Watir when they already fit

Selenium

If the application already uses Selenium WebDriver, using its Ruby API avoids introducing a separate browser-control approach just for screenshots. The official Ruby documentation shows navigation, locating an element, and saving that element’s screenshot. The API also documents:

driver.save_screenshot("page.png", full_page: false)

The full_page option and default shown here are Selenium-specific; do not assume the same behavior or argument names apply to Ferrum or another library.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Watir

Watir’s documented screenshot methods include saving the screenshot object to a path and retrieving PNG or Base64 data:

browser.screenshot.save "screenshot.png"
png_data = browser.screenshot.png
base64_data = browser.screenshot.base64

Use the forms documented by the version in your application. Cuprite is another reasonable route when the project already uses Capybara and needs a headless Chrome or Chromium driver; it is built on Ferrum.

Or skip the browser setup

If you need a screenshot endpoint rather than managing a browser in the Ruby runtime, ScreenshotNeo returns a screenshot or PDF from one GET request. Its clean-shot options accept cookie or consent banners as a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing outcome. It also provides an MCP server with take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients.

See the ScreenshotNeo API documentation. Example request:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

The response can be PNG, JPEG, WebP, or PDF depending on the request. The API also supports full-page capture with lazy images loaded, CSS-selector element capture, viewport/device settings, custom CSS and JavaScript, waits, request blocking, caching, signed links, asynchronous jobs, and bulk capture. Free includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000, with every feature on every plan. Create a free account and get 1,000 screenshots a month with no card.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common capture problems

Ferrum cannot start the browser

Likely cause: Chrome or Chromium is missing or not discoverable by the process. Fix: install a supported browser for the target environment, make the binary available through PATH or BROWSER_PATH, or configure browser_path as described in Ferrum’s current docs.

The screenshot is blank or missing dynamic content

Likely cause: capture occurred before the page or client-side content was ready, or the destination itself returned a blank or blocked page. Fix: inspect the page state before capture and wait for a target-specific readiness condition. Do not treat an arbitrary fixed delay as reliable for all sites.

The image contains only part of the page

Likely cause: the default viewport capture was used. Fix: use full: true for Ferrum’s full-document mode, or the corresponding documented option for the library in use. For a particular component, target its selector rather than requesting the whole page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The wrong region was captured

Likely cause: incompatible Ferrum scope options were combined. Fix: choose one of viewport, full page, selector, or area. In particular, full: true overrides selector and area, while selector takes precedence over area when both are present.

A file exists but another tool cannot read it

Likely cause: the caller expected a different format or encoding. Fix: use path: for a file and rely on PNG’s documented default, or request the format and encoding explicitly when returning data in memory. Confirm downstream code expects the selected image format.

Plan for performance, reliability, and cost

With a local browser, browser startup and page loading are part of the capture job; the cited materials do not provide a performance benchmark or universal timing guarantee. For repeated captures, avoid leaving browser processes open unintentionally, close them in an ensure block, and impose application-level timeouts and error handling. A capture may fail because of browser setup, network availability, target-site behavior, or content readiness, so preserve enough logging to distinguish navigation failures from screenshot-option mistakes.

Ruby libraries in this workflow have no per-image service price established by the cited documentation; operational costs depend on the environment running Ruby and Chrome or Chromium. If captures need to run across a service without packaging and maintaining that browser runtime, compare the hosted API route against the operational requirements and budget. Do not assume a library has a particular browser-version, operating-system, or Ruby-version compatibility without checking the current project documentation for your deployment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Does Ferrum save screenshots as PNG by default?

Yes. Its screenshot API defaults to PNG, and a supplied path writes the image to disk.

Does Ferrum require ChromeDriver?

No. Ferrum documents that it uses CDP and does not depend on Selenium, WebDriver, or ChromeDriver, but it still requires a Chrome or Chromium binary.

Can I capture just one CSS element in Ruby?

Yes. Ferrum documents a selector: screenshot option; Selenium’s Ruby documentation also demonstrates saving an element screenshot.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.