Back to directory
rubycdp avatar

ferrum

Headless Chrome Ruby API. Read more below about its uses, features, and usage.

Clone repository

git clone https://github.com/rubycdp/ferrum.git

2,039

Stars

169

Forks

25

Watchers

MIT

License

Ferrum - high-level API to control Chrome in Ruby

Documentation

Ferrum logo

It is Ruby clean and high-level API to Chrome. Runs headless by default, but you can configure it to run in a headful mode. All you need is Ruby and Chrome or Chromium. Ferrum connects to the browser by CDP protocol and there's no Selenium/WebDriver/ChromeDriver dependency. The emphasis was made on a raw CDP protocol because Chrome allows you to do so many things that are barely supported by WebDriver because it should have consistent design with other browsers.

  • Cuprite is a pure Ruby driver for Capybara based on Ferrum.
  • Vessel high-level web crawling framework based on Ferrum and Mechanize.

Install

There's no official Chrome or Chromium package for Linux don't install it this way because it's either outdated or unofficial, both are bad. Download it from official source for Chrome or Chromium. Chrome binary should be in the PATH or BROWSER_PATH and you can pass it as an option to browser instance see :browser_path in Customization.

Add this to your Gemfile and run bundle install.

gem "ferrum"

Quick Start

Navigate to a website and save a screenshot:

browser = Ferrum::Browser.new
browser.go_to("https://google.com")
browser.screenshot(path: "google.png")
browser.quit

When you work with browser instance Ferrum creates and maintains a default page for you, in fact all the methods above are sent to the page instance that is created in the default_context of the browser instance. You can interact with a page created manually and this is preferred:

browser = Ferrum::Browser.new
page = browser.create_page
page.go_to("https://google.com")
input = page.at_xpath("//input[@name='q']")
input.focus.type("Ruby headless driver for Chrome", :Enter)
page.at_css("a > h3").text # => "rubycdp/ferrum: Ruby Chrome/Chromium driver - GitHub"
browser.quit

Evaluate some JavaScript and get full width/height:

browser = Ferrum::Browser.new
page = browser.create_page
page.go_to("https://www.google.com/search?q=Ruby+headless+driver+for+Capybara")
width, height = page.evaluate <<~JS
  [document.documentElement.offsetWidth,
   document.documentElement.offsetHeight]
JS
# => [1024, 1931]
browser.quit

Do any mouse movements you like:

# Trace a 100x100 square
browser = Ferrum::Browser.new
page = browser.create_page
page.go_to("https://google.com")
page.mouse
  .move(x: 0, y: 0)
  .down
  .move(x: 0, y: 100)
  .move(x: 100, y: 100)
  .move(x: 100, y: 0)
  .move(x: 0, y: 0)
  .up

browser.quit

Development

After checking out the repo, run bundle install to install dependencies.

Then, run bundle exec rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub.

License

The gem is available as open source under the terms of the MIT License.

Releases

Aug 20, 2026

0.18.0

Download .zip

Added

Ferrum::Browser option :protocol_timeout bounds individual internal CDP bookkeeping calls, e.g. Target.createTarget, Target.attachToTarget. It's a separate setting from :timeout: its default (5...

Mar 24, 2026

0.17.2

Download .zip

Added

Ferrum::Network::Response#body! returns body or throws error if implicable Ferrum::Browser#new(dockerize: true) whether to add CLI flags to run a browser in a container, false by default Initia...

May 11, 2025

0.17.1

Download .zip

Fixed

Can't use single quotes in screenshot :selector [#465] remote_debug_url for modern Chrome returns chrome-devtools-frontend.appspot.com absolute url

May 10, 2025

0.17

Download .zip

Added

Ferrum::Network::Exchange#blob? determines if the exchange is blob [#516] Ferrum::Network::Request#headers are enhanced and supplemented with Network.requestWillBeSentExtraInfo [#506] Ferrum::P...

Dec 1, 2024

0.16

Download .zip

Added

Ferrum::Network#wait_for_idle! raises an error if timeout reached. Ferrum::Browser#close closes browser gracefully issuing a CDP command, doesn't clean up ruby resources. Ferrum::Node#remove re...