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.

PhantomJS does not provide a selector argument to page.render(). To capture one element, find its rendered rectangle, assign that rectangle to page.clipRect, and render after the page is visually ready. The rectangle must contain top, left, width, and height values in the same coordinate space as the page viewport.

What PhantomJS actually captures

The documented PhantomJS workflow captures a portion of the page, not a DOM node by selector. page.clipRect defines that portion, and page.render() writes it to an image or PDF. Passing a CSS selector directly to page.render() does not turn the selector into an element screenshot.

That means the job has three stages:

  1. Open the page and wait for a successful load.
  2. Measure the target element’s rendered position and dimensions.
  3. Copy those measurements into page.clipRect, then call page.render().

Complete PhantomJS example

The following script measures an element with getBoundingClientRect(), converts its rectangle to page coordinates, and captures it. Change the URL and selector to match your page.

var page = require('webpage').create();

page.viewportSize = { width: 1024, height: 768 };
var targetUrl = 'https://example.com/';
var selector = '.hero';

page.open(targetUrl, function (status) {
  if (status !== 'success') {
    console.error('Unable to load the page');
    phantom.exit(1);
    return;
  }

  var rect = page.evaluate(function (sel) {
    var element = document.querySelector(sel);
    if (!element) {
      return null;
    }

    var box = element.getBoundingClientRect();
    return {
      top: box.top + window.pageYOffset,
      left: box.left + window.pageXOffset,
      width: box.width,
      height: box.height
    };
  }, selector);

  if (!rect || rect.width <= 0 || rect.height <= 0) {
    console.error('Target element was not found or has no visible size');
    phantom.exit(1);
    return;
  }

  page.clipRect = {
    top: rect.top,
    left: rect.left,
    width: rect.width,
    height: rect.height
  };

  page.render('element.png');
  phantom.exit();
});

The numeric values in the official example (top: 120, left: 80, width: 400, and height: 220) are illustrative, not measurements of a particular page. Always calculate them for the document you are rendering.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Why add the scroll offset?

getBoundingClientRect() reports coordinates relative to the viewport. page.clipRect needs a page-region rectangle, so adding window.pageYOffset and window.pageXOffset keeps the crop aligned when the document has scrolled. If your PhantomJS version or page behavior uses a different coordinate interpretation, verify the result with a test capture.

Waiting until the element is ready

A successful page.open() callback means the navigation completed; it does not prove that JavaScript widgets, web fonts, images, or lazy content have settled. Measuring too early can produce a zero-sized rectangle or a crop missing late content.

Wait for a known condition

For dynamic pages, poll for the selector and a positive size before measuring. A simple pattern is to use window.setInterval in PhantomJS and stop when the element exists, has dimensions, and (if relevant) a page-specific readiness flag is true.

var tries = 0;
var timer = window.setInterval(function () {
  tries += 1;
  var ready = page.evaluate(function (sel) {
    var el = document.querySelector(sel);
    if (!el) return false;
    var r = el.getBoundingClientRect();
    return r.width > 0 && r.height > 0;
  }, selector);

  if (ready || tries > 100) {
    window.clearInterval(timer);
    // Measure the element and call page.render() here.
  }
}, 100);

Use a page-specific condition when possible, such as a class added after data loading. A fixed sleep can be useful for a simple prototype, but it is not proof that asynchronous work has finished.

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

Coordinate, layout, and viewport pitfalls

Scrolling

If the target is below the initial viewport, scroll the page before measurement or use document coordinates as shown above. Recalculate the rectangle after scrolling because its viewport-relative position changes.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Responsive layout

Set page.viewportSize before opening the page. Breakpoints can change the element’s width, position, or even markup. A rectangle measured at one viewport should not be reused at another.

Late fonts and images

Web fonts can change line wrapping, while images without fixed dimensions can expand a container after load. Wait for the page’s own ready signal or for the relevant assets to be present, then measure immediately before rendering.

Transforms and fractional pixels

CSS transforms and fractional dimensions may yield non-integer values. PhantomJS can handle many such values, but rounding the rectangle to integers can make output more predictable. If rounding, keep the right and bottom edges consistent so you do not lose a pixel at either edge.

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

Overflow and nested scrolling

An element inside a scrollable container may have content that is not currently painted. A clip rectangle captures the rendered region; it does not automatically expand a nested scroller to reveal hidden content. Adjust the container’s scroll position or capture the container itself.

Output formats and rendering choices

The PhantomJS guide lists PNG, JPEG, GIF, and PDF output. Use an image extension for a screenshot:

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
  • PNG: lossless output suited to interfaces, text, and transparency.
  • JPEG: smaller files with lossy compression; transparency is not preserved.
  • GIF: supported by the documented renderer, but generally limited for modern screenshots.
  • PDF: useful for documents rather than a pixel-focused element image.

Call page.render() only after assigning page.clipRect. Rendering before the assignment captures the default page region instead of the target.

Production checklist

  • Set a deterministic viewport before navigation.
  • Check that page.open() returned success.
  • Wait for the selector and a non-zero rectangle.
  • Include scroll offsets when converting viewport coordinates.
  • Measure again after any scroll, resize, or state change.
  • Choose an output extension that matches the required format.
  • Exit with a non-zero status when loading or measurement fails.
  • Keep a diagnostic full-page capture while debugging clipping problems.

Troubleshooting

“Unable to load the page”

Cause: navigation failed, redirected unexpectedly, or the site is inaccessible to the PhantomJS runtime. Fix: log the final URL and page errors, verify the address from the same environment, and fail the job rather than rendering an empty page.

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.

The output is blank

Cause: the page or target had not rendered, the rectangle dimensions were zero, or the crop was outside the document. Fix: print the measured rectangle, wait for a page-specific readiness condition, and confirm the viewport and scroll coordinate system.

The element is cut off

Cause: a parent has overflow, content is in a nested scroller, or the measured box excludes visual effects. Fix: scroll the relevant container, capture the correct ancestor, or add a deliberate margin to the clip rectangle.

The screenshot contains a cookie banner, popup, or chat widget

Cause: PhantomJS renders those elements like a normal visitor unless your script dismisses or hides them. Fix: automate the page’s consent control, inject narrowly scoped CSS, or remove the overlay before measuring. Do not hide the target accidentally.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Text differs from a modern browser

Cause: PhantomJS uses a QtWebKit backend with older browser behavior. Fix: treat the image as PhantomJS-specific, or move the workflow to a maintained browser automation engine when modern CSS and JavaScript fidelity matter.

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

Is PhantomJS still a good choice?

The PhantomJS project homepage states: “Important: PhantomJS development is suspended until further notice (more details).” That status matters for security, standards support, and maintenance planning. An existing script may remain adequate when its pages are stable and its output is accepted, but new projects should compare maintenance status, browser behavior, waiting and scrolling semantics, runtime requirements, and output options.

Playwright

Playwright documents await page.locator('.header').screenshot({ path: 'screenshot.png' });. Its locator screenshot captures the matched element, scrolls it into view, performs actionability checks, and throws if the element detaches. Covered content and off-screen portions of a scrollable container still have visibility limitations.

Puppeteer

Puppeteer documents ElementHandle.screenshot() for an individual element and says it attempts to scroll a hidden element into view. Review the current API documentation before relying on behavior that may change between versions.

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

Or skip the browser setup

ScreenshotNeo is a hosted screenshot API and MCP server. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not charged, and response headers report the page verdict and billing result.

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

For a one-call capture, see the ScreenshotNeo API documentation:

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

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)

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}`);

ScreenshotNeo also supports CSS-selector element capture, full-page lazy-image loading, custom CSS and JavaScript, waits, device and viewport settings, PDF output, request blocking, cookies and headers, caching, signed links, asynchronous webhooks, bulk capture, and an MCP server with take_screenshot, get_page_info, and capture_pdf for AI clients. Every plan includes every feature. The free plan provides 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Cost and reliability considerations

A local PhantomJS script has no per-shot API charge, but you own browser installation, page compatibility, retries, output storage, and cleanup logic. Dynamic sites can fail intermittently, so record navigation status, measured dimensions, render errors, and the final file path. A hosted service shifts those concerns to an API request; inspect its verdict and billing headers so failed or unclean captures are distinguishable from successful screenshots.

Frequently Asked Questions

Can I pass a CSS selector directly to PhantomJS page.render()?

No. Measure the selected element’s rendered rectangle and assign its top, left, width, and height to page.clipRect before rendering.

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

Which file extension should I use for a transparent element screenshot?

Use PNG when you need lossless output or transparency. JPEG, GIF, and PDF are also listed as supported PhantomJS render outputs, with different suitability for interface screenshots.

Why does my crop move when I scroll?

getBoundingClientRect() is viewport-relative. Add page offsets for document coordinates, or measure after scrolling and keep the clip rectangle in the coordinate system PhantomJS uses.

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.