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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Ruby can capture a website through a hosted screenshot API using either the provider’s gem or a standard HTTP client. The basic flow is to keep the API key on your server, send a target URL and supported capture options, then save the returned image bytes or use a generated image URL. SDK method names, authentication, output handling and capture options vary by provider, so follow the selected API’s current documentation.

Choose an SDK or make an HTTP request

A screenshot API runs the browser and returns a capture, so your Ruby application does not need to install or manage a local browser for that capture. A vendor gem can make common requests more convenient; ordinary HTTP is useful when the provider has no Ruby SDK or the SDK does not expose an option you need.

  • Use the official SDK when it supports your Ruby environment and the capture controls your application requires. Check its current installation instructions, option names and response type.
  • Use HTTP when you want a small integration or direct access to a documented endpoint. You must implement request construction, timeouts, response validation and error handling yourself.

These are integration examples, not interchangeable APIs. ScreenshotOne documents a Ruby gem and client, while html2img documents a distinct Ruby client and option set. Their methods and parameters are provider-specific: ScreenshotOne Ruby SDK and Code Examples, ScreenshotOne Ruby SDK repository, and html2img Ruby integration.

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

Keep the API key on the server

Do not put a screenshot API key in browser-delivered JavaScript, an HTML page, a mobile app bundle or a public repository. Anyone who can extract it may be able to make requests against your account. The html2img Ruby library is intended for server-side use and warns that exposing its key can let others spend account credits: html2img’s Ruby library.

#1 Best Overall

For a Rails application, keep the key in a deployment secret or environment variable and read it from server-side code. For example:

SCREENSHOT_API_KEY=your_real_key

Do not commit a real value in a checked-in .env file. In Rails, access a configured secret through your application’s credentials or environment configuration rather than passing it to a view. Also avoid logging full request URLs if the provider accepts credentials in the query string.

Use ScreenshotOne’s Ruby SDK

ScreenshotOne’s documented Ruby flow installs the screenshotone gem, creates a ScreenshotOne::Client with an access key and optional secret key, and builds TakeOptions with a URL. The client can generate a take URL or return image data through take. The exact gem version and current option support should be checked in the provider’s documentation before copying this into a production app.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Add the gem: include gem "screenshotone" in your Gemfile and run bundle install.
  2. Load credentials server-side: configure the access key as a secret or environment variable.
  3. Build options: supply the page URL and only options supported by ScreenshotOne.
  4. Save the response: write the image response body to a file or another storage destination appropriate for your application.
require "screenshotone"

access_key = ENV.fetch("SCREENSHOTONE_ACCESS_KEY")
client = ScreenshotOne::Client.new(access_key: access_key)
options = ScreenshotOne::TakeOptions.new(url: "https://example.com")

image_response = client.take(options)
File.binwrite("page.png", image_response.body)

Use the response format and file extension that match the format you request from the provider. The SDK repository shows option examples including full_page, delay and geolocation; these are ScreenshotOne-specific, not universal Ruby screenshot parameters. If you need the provider to return a URL rather than bytes, its documented generate_take_url method is another path. See the official Ruby guide and SDK repository for the current method signatures.

Use another provider’s Ruby client only with its own options

html2img’s Ruby integration illustrates why a provider’s reference matters. It documents a client screenshot call and options such as viewport dimensions, selector targeting, CSS injection, DPI and full-page capture. It also documents waiting for a selector or adding a delay when content appears after initial page load. These controls should not be assumed to exist under the same names—or at all—in another service’s SDK. Consult the html2img integration guide for that client’s current construction and request syntax.

Call an API with Ruby’s standard HTTP library

If you do not want a gem, Ruby’s standard libraries can make an HTTPS GET request. The endpoint, authentication location, query parameter names, accepted formats and error response format must come from the API you choose. The example below is specifically for ScreenshotNeo’s documented GET endpoint; do not reuse its request shape with another provider.

Save this as screenshot.rb, set SCREENSHOTNEO_API_KEY in the server environment, and run ruby screenshot.rb. It sends the key and target URL as query parameters, checks for a successful HTTP response and writes the returned bytes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
require "net/http"
require "uri"

api_key = ENV.fetch("SCREENSHOTNEO_API_KEY")
params = {
  "access_key" => api_key,
  "url" => "https://stripe.com"
}
uri = URI("https://api.screenshotneo.com/v1/shot")
uri.query = URI.encode_www_form(params)

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.open_timeout = 10
http.read_timeout = 90

response = http.get(uri.request_uri)
unless response.is_a?(Net::HTTPSuccess)
  abort "Screenshot request failed: HTTP #{response.code}"
end

File.binwrite("shot.webp", response.body)
puts "Saved shot.webp"

This saves the response body as WebP, matching the filename used in the request examples. For any provider, confirm the selected output format and inspect response headers or documented errors before treating every successful response as an image. Keep the key private even though query parameters are convenient; URLs can appear in application, proxy or server logs.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server for developers. It takes one GET request to return a PNG, JPEG, WebP or PDF. Its clean-shot processing accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info and capture_pdf for Claude, Cursor and other MCP clients.

Ruby example:

require "net/http"
require "uri"

uri = URI("https://api.screenshotneo.com/v1/shot")
uri.query = URI.encode_www_form(
  "access_key" => ENV.fetch("SCREENSHOTNEO_API_KEY"),
  "url" => "https://stripe.com"
)
response = Net::HTTP.get_response(uri)
raise "Screenshot failed: HTTP #{response.code}" unless response.is_a?(Net::HTTPSuccess)
File.binwrite("shot.webp", response.body)

The same request in cURL, Python and Node.js, along with the API reference, is in the ScreenshotNeo documentation. Its free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Every feature is available on every plan, including full-page captures with lazy images, CSS-selector element capture, 12 device presets and custom viewports, PDF controls, custom CSS and JavaScript, waits, request blocking, custom headers and cookies, caching, signed image links, async jobs, bulk capture up to 100 URLs per call, and a usage API. Use the free sign-up to start with 1,000 screenshots a month and no card.

Choose capture settings deliberately

Before adding options to a Ruby request, decide what the saved image must contain. A default viewport screenshot captures only the visible area; a full-page capture is different and may require the service to scroll the page or load lazy content. Selector cropping is useful for a chart or card, but it depends on the element existing when the capture runs. Wait options can help with client-rendered content, though an unnecessarily long fixed delay adds time to every job.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Viewport and device: set dimensions or a documented device preset when layout consistency matters. Device emulation and viewport size are separate from image scale or retina output.
  • Timing: prefer a selector-based wait when the page has a reliable element indicating readiness. Use a delay only when the site offers no dependable readiness signal. Network-idle behavior can also be provider-specific.
  • Page changes: custom CSS, JavaScript, clicks, hidden selectors and element capture are powerful but can change the result. Keep them narrowly scoped and validate the final output.
  • Access controls: pass cookies, headers or authorization only through documented secure features, and only when authorized to capture that page.
  • Output and storage: request the format and dimensions your downstream use needs. Avoid saving a very large full-page image if a specific element or viewport is sufficient.

Options documented for one provider do not imply support in another. The html2img guide describes an anonymous request from the public internet; a protected route can therefore render a sign-in screen rather than the page a user sees when logged in. Its documentation states: “A capture is an anonymous request from the public internet, so an authenticated route comes back as your sign-in page.” Check the provider’s documented authenticated-capture support instead of assuming it can reuse a visitor’s browser session: html2img Ruby integration.

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

Handle failures and make jobs observable

A screenshot response is an external service call, so treat it like any other dependency in a backend job. Set connection and read timeouts, check the HTTP status, and distinguish a transport failure from an image result. Do not blindly retry every error: an invalid URL or unsupported option will not be fixed by repeating the same request, while a transient network failure may be worth a limited retry under your job system’s policy.

  • Authentication error: confirm the environment variable is present in the process that runs the job, that the key belongs to the selected service, and that it has not been revoked. Do not print the key while debugging.
  • Bad request: check that the URL is encoded as a single parameter and that option names and values match the provider’s current API reference.
  • Timeout: verify the target is reachable from the provider’s capture environment and that your timeout accommodates the expected rendering time. A slow page may need an appropriate wait, but longer waits increase job duration.
  • Unexpected sign-in page: the capture service may be making an anonymous public request. Confirm whether that provider supports authorized access and pass credentials only through its documented, secure mechanism.
  • Blank or incomplete capture: check whether the site needs JavaScript rendering, a selector wait, lazy-image loading or a different viewport. Test with the smallest setting change that addresses the observed issue.
  • File is not a usable image: inspect the HTTP status and response metadata before writing bytes. An error response can contain text or JSON even if the filename ends in .png or .webp.

For production workflows, record a request identifier if the provider supplies one, the target host, elapsed time, status and output size. Redact credentials, sensitive query strings and private page content. A queue is usually a better place for captures that do not need to finish during a web request: it keeps slow rendering from holding a user-facing request open and gives the application a place to apply bounded retry rules.

Questions developers often ask

Does Ruby need a browser installed?

Not when the hosted screenshot API runs the browser for you. A local-browser approach is a separate architecture with its own installation and maintenance requirements.

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

Can I capture a page that requires a login?

Only if the selected provider supports a documented authentication method and you are authorized to use it. A public anonymous capture of a protected route may show the sign-in page.

Should I use the SDK or HTTP in a Rails app?

Choose the maintained provider SDK if its current Ruby support and exposed features fit your application. Otherwise, HTTP gives you direct control, but you must handle request construction, timeouts, response validation and errors yourself.

Can I use ScreenshotOne options with ScreenshotNeo or html2img?

No. Verify option names and behavior against the API you actually call; similarly named features do not guarantee identical semantics or support.

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.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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