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
World desk5 min

How to Capture a Webpage Screenshot with a Screenshot API in Ruby

Use a hosted screenshot API from Ruby to capture a webpage, configure viewport and timing options, and understand remote-rendering limits.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To capture a webpage from Ruby, send its URL to a hosted screenshot API and save or use the returned image. The API’s renderer loads the page and takes the shot, so you do not need to run a browser in your Ruby app. This example uses html2img’s documented Ruby client; its requirements and option names apply to that provider, not to every screenshot API.

Capture a page with the html2img Ruby client

The html2img Ruby guide documents Ruby 3.1 or newer and an API key. Install the gem, store the key in a server-side environment variable, then call screenshot with the target URL and viewport dimensions:

As an Amazon Associate I earn from qualifying purchases.

  1. Install the client: gem install html2img.

  2. Set your API key in the environment as HTML2IMG_API_KEY. Do not put the key in browser-side JavaScript or public source code.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Save this as screenshot.rb and run it with Ruby:

require "html2img"

client = Html2img::Client.new(api_key: ENV.fetch("HTML2IMG_API_KEY"))
response = client.screenshot(
  "https://example.com",
  width: 1200,
  height: 630
)

puts response.url

The documented response includes a URL and status information. This example prints the returned URL; check the provider’s current response documentation for the exact fields and how long a result remains available.

#1 Best Overall

See the html2img Ruby guide for the current client setup and options. The Ruby client README documents the response shape and request behavior. The code above illustrates the documented syntax; it has not been independently tested here.

Choose what the screenshot includes and when it is taken

Viewport, full page, or one element

Wait for dynamic content

Pages that populate after their initial load may need extra time before capture. The guide documents wait_for_selector and ms_delay. Prefer waiting for a known element that indicates the content is ready; a fixed delay is simpler but cannot tell whether loading finished early or is still in progress.

Hide overlays with injected CSS

CSS injection can hide a cookie banner, chat widget, or other overlay. A site’s own styles may override your rule, so the guide notes that adding !important can be necessary. Check the selector against the actual page; a rule that matches nothing will not remove the overlay.

Know what the remote renderer can access

A hosted screenshot API renders the page from its own environment. The html2img guide says captures are anonymous: if the requested route requires a login, the result will generally show what an unauthenticated visitor sees, such as the sign-in page. Do not assume private pages can be captured. Use an authenticated-capture feature only if the provider documents it and you have assessed how credentials are handled.

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

Resources referenced by the page must also be reachable by that remote renderer. The html2img README says localhost resources do not resolve from its renderer. A local development server or assets available only inside your network therefore will not be visible to it.

Handle long captures and failures

Synchronous request timing

The html2img README gives synchronous requests a 30-second budget. A page that takes longer may not return a completed screenshot through that path. For longer work, its documentation describes webhook delivery; handle the processing response and wait for the webhook before relying on a final result URL.

Common problems and fixes

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

Hosted API or browser automation in Ruby?

A hosted API lets your Ruby code make an HTTP request while the provider operates the rendering environment. Browser automation, such as Puppeteer Ruby, gives your application more direct control but means your team must operate that browser stack. The available documentation establishes these different implementation responsibilities, not a general performance, reliability, or price winner. Choose based on whether you want a managed capture endpoint or control over the browser environment, and verify each provider’s access model, capture options, response format, and long-job handling.

Or skip the browser setup

ScreenshotNeo is a screenshot API and MCP server for developers. One GET request returns an image or PDF. Its API removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. AI agents can take screenshots through its MCP server.

For example, save a WebP response to a file with cURL:

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo API documentation for authentication and response details. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month, no card required.

FAQ

Can I capture a page behind a login?

With the documented html2img flow, captures are anonymous, so a protected page generally returns its unauthenticated view. A provider-specific authenticated-capture feature would need to be documented separately.

Does this example save the image directly to disk?

No. It prints the response URL. Use the provider’s current response documentation to retrieve or otherwise use the image from that URL.

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 *

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
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.