Use Ferrum to drive Chrome or Chromium from Ruby, navigate to a URL, and save a screenshot. Ferrum runs headlessly by default and communicates through the Chrome DevTools Protocol (CDP), so Selenium, WebDriver, and ChromeDriver are not required. The minimal workflow is to create a browser, call go_to, call screenshot, and always close the browser.
What you need before writing the script
- Ruby installed and available on your command path.
- The Ferrum gem in your bundle.
- Chrome or Chromium installed. Ferrum expects the executable on
PATH, or you can provide a browser path in its configuration. Use an official Chrome or Chromium distribution. - A URL that the browser process can reach from the machine where Ruby runs.
Ferrum does not download or bundle a browser for you. In containers and CI systems, install a compatible Chrome/Chromium package and make its path explicit when it is not on PATH.
Install Ferrum and take your first screenshot
Add Ferrum to a Bundler project:
bundle add ferrum
Then create screenshot.rb:
require "ferrum"
browser = Ferrum::Browser.new
begin
browser.go_to("https://example.com")
browser.screenshot(path: "example.png")
ensure
browser.quit
end
Run it with ruby screenshot.rb. A PNG named example.png is written in the current directory. The ensure block matters: it closes Chrome even when navigation or capture raises an exception.
Use an explicit page for longer workflows
For scripts that interact with a page, create a page object and capture it. This makes multiple pages or browser contexts easier to manage:
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
- CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
- WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
- A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
require "ferrum"
browser = Ferrum::Browser.new
begin
page = browser.create_page
page.go_to("https://example.com")
page.screenshot(path: "page.png")
ensure
browser.quit
end
Close the browser after all pages are finished. A long-running process should also close pages or contexts that it no longer needs.
Choose the capture area and output format
Ferrum supports viewport screenshots by default, full-page captures, element captures, rectangular areas, and returning image data as base64. PNG is the default; JPEG/JPG and WebP are also available, with quality settings for the lossy formats.
Viewport versus full page
page.screenshot(path: "viewport.png")
page.screenshot(path: "whole-page.png", full: true)
A viewport shot records only what is visible in the browser viewport. A full-page shot extends the capture over the document’s page height, which is useful for documentation and visual regression artifacts.
Capture one element
page.screenshot(path: "header.webp", selector: "header", format: "webp", quality: 85)
Use a stable CSS selector. If the selector does not match, the capture fails rather than silently producing an unrelated image.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCapture a rectangle
When you need a coordinate area instead of a DOM element, supply a rectangular region using Ferrum’s area options. Keep the coordinates tied to a known viewport size; responsive layouts can move the same content at another width.
Rank #2
- CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
- SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
JPEG, WebP, and base64
page.screenshot(path: "card.jpg", format: "jpeg", quality: 80)
image_base64 = page.screenshot(format: "webp", quality: 85, encoding: :base64)
Use PNG when lossless text and transparency matter. JPEG is smaller for photographic content but does not preserve transparency. WebP can reduce size when your downstream consumer accepts it. Base64 is useful when an API response or database record must carry the image rather than a file.
Control the browser before capturing
Set a predictable viewport
Responsive pages can produce different layouts at different widths. Configure the browser or page viewport before navigation so local runs and CI runs use the same dimensions. Record that viewport as part of your visual-test configuration.
Wait for dynamic content
Navigation completing does not guarantee that a chart, image, or client-rendered component is ready. Wait for a selector that represents the finished state, or use a deliberate delay when no reliable selector exists. A selector wait is generally less wasteful than a fixed long sleep because it ends as soon as the element appears.
page.go_to("https://example.com/dashboard")
page.at_css("[data-rendered='true']")
page.screenshot(path: "dashboard.png", full: true)
For pages whose content depends on network activity, combine a meaningful readiness condition with a bounded timeout. Avoid waiting forever on an analytics request that never completes.
Authentication and state
If the target requires login, establish the session before capture using the page’s normal browser interactions or configured cookies and headers. Do not place credentials in source control. For repeatable runs, use a dedicated test account and a secret manager.
Rank #3
- Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
- Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
- Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
- In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
- Ultra-thin bezels: Maximize your viewing experience with thin bezels.
Reusable Ruby examples
Command-line URL and output path
require "ferrum"
url = ARGV.fetch(0)
output = ARGV.fetch(1, "shot.png")
browser = Ferrum::Browser.new
default_page = nil
begin
default_page = browser.create_page
default_page.go_to(url)
default_page.screenshot(path: output, full: true)
puts "Saved #{output}"
ensure
browser.quit
end
Invoke it as ruby capture.rb https://example.com example.png. Validate or restrict accepted URLs if this script is exposed as a service; unrestricted URL fetching can create a server-side request-forgery risk.
Capture several URLs with one browser
require "ferrum"
browser = Ferrum::Browser.new
begin
{
"home" => "https://example.com",
"about" => "https://example.com/about"
}.each do |name, url|
page = browser.create_page
begin
page.go_to(url)
page.screenshot(path: "#{name}.png", full: true)
ensure
page.close
end
end
ensure
browser.quit
end
Reusing one browser avoids launching a new Chrome process for every URL, while closing each page prevents unbounded resource growth.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →PDF output and Capybara integration
Ferrum also exposes PDF export with paper-size and orientation controls. Use it when the deliverable is a paginated document rather than a raster image; verify page breaks on the actual content because CSS and print layout can differ from the screen.
If screenshots belong inside a Capybara test suite, Cuprite is Ferrum-based and provides a pure-Ruby Capybara driver. This keeps browser-driven assertions and capture operations in the same CDP-oriented stack instead of adding Selenium/WebDriver.
When a capture fails: diagnosis and fixes
“Browser executable not found”
Chrome or Chromium is absent, or it is not on PATH. Install it from an official source, confirm the executable runs under the same user as Ruby, or configure Ferrum with the executable’s path.
Rank #4
- CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
- SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
- MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
- KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
- INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
Chrome starts and exits immediately
Check the browser and Ferrum logs, available shared memory, sandbox restrictions, and permissions in the runtime. Containers often need a properly sized shared-memory mount and a browser configuration appropriate for that container. Do not disable security controls indiscriminately; fix the container permissions and isolation first.
The image is blank or incomplete
The page may still be rendering, may require authentication, or may block the runtime. Confirm the URL manually from the same machine, wait for a page-specific readiness selector, and inspect the final URL for redirects. For lazy-loaded pages, scroll or use a full-page strategy that causes content to load before capture.
A selector capture raises an error
Verify the selector in the page’s actual DOM, account for frames or shadow roots, and wait until the component is rendered. Prefer a stable test attribute over a presentation class that changes with a redesign.
Different results in CI and on a laptop
Pin the viewport, browser channel, fonts, timezone, and test data. Differences in installed fonts, device scale, animation timing, and network access can all alter pixels. Disable or wait out animations when deterministic output is required.
Memory and throughput problems
Each browser and page consumes resources. Reuse a browser for a batch, close pages promptly, cap concurrency, and write files incrementally. If one page leaks resources, isolate it in a short-lived browser process rather than allowing a long-running worker to degrade indefinitely.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Best Value
- 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
- 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
- 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
Or skip the browser setup
ScreenshotNeo is a hosted website screenshot API and MCP server. A single GET request returns PNG, JPEG, WebP, or PDF. It accepts cookie and consent banners like a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets before the capture; each cleanup step can be disabled. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
Install no Chrome locally. The API supports full pages with lazy images, CSS-selector elements, dark mode, 12 device presets or custom viewports, retina scale, PDF paper settings and page ranges, custom CSS and JavaScript, pre-capture clicks, hidden selectors, waits, request/resource blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, selectable cache TTLs, signed image links, asynchronous jobs with signed webhooks, 100-URL bulk calls, usage data, and an OpenAPI specification. Common parameter names used by other screenshot APIs are accepted to ease migration.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo documentation for all options. The same request in Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
And in Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
The Free plan includes 1,000 screenshots each month with no card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free. Create a free ScreenshotNeo account to start.
Cost and reliability decisions
Ferrum has no hosted per-shot charge, but you operate Chrome, fonts, networking, storage, and maintenance. It is a good fit when data must remain in your environment, a test already uses Ruby, or you need browser-level control. A hosted API is simpler for scheduled jobs and deployments where installing and patching Chrome is undesirable. Whichever route you choose, log the URL, viewport, output format, browser or API response status, and capture duration so a changed image can be diagnosed rather than guessed.
Frequently Asked Questions
Can Ferrum capture a page without Selenium?
Yes. Ferrum communicates with Chrome or Chromium through CDP and does not require Selenium, WebDriver, or ChromeDriver.
Which format should I use for screenshots?
Choose PNG for lossless text or transparency, JPEG for photographic images where some compression is acceptable, and WebP when your consumer supports it and smaller files are useful.
Is Ferrum suitable for Capybara?
Yes. Cuprite is a pure-Ruby Capybara driver built on Ferrum.
Free tools Windows power users keep installed
One-click scans. No signup required.
Quick Recap
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.

