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

To capture a web page with PhantomJS, create a webpage, set its viewportSize before opening the URL, check the page-open status, and call page.render() only after the content you need is ready. Use clipRect to crop the output. For crisp interface text, PNG is a sensible default; for JPEG, choose a quality value that balances image appearance and file size.

PhantomJS’s documentation describes its WebKit-based capture workflow, but it does not establish compatibility with current websites or systems. Test against the actual page and environment before relying on it.

Capture a page with PhantomJS

The basic workflow is to set the viewport, open the page, handle a failed load, render the result, and exit. Save this as capture.js and run it with the PhantomJS executable available in your environment:

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

// Choose the viewport whose responsive layout you want to capture.
page.viewportSize = { width: 1280, height: 900 };

page.open('https://example.com/', function (status) {
  if (status !== 'success') {
    console.log('Unable to load the address!');
    phantom.exit(1);
    return;
  }

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

Run it with phantomjs capture.js. The 1280-by-900 viewport is an example, not a universal best setting: use the dimensions that produce the page layout you intend to show. PhantomJS’s viewportSize reference requires both width and height. Set them before navigation because viewport width can change responsive layout and the height determines the visible viewport area. See the viewportSize reference and PhantomJS Quick Start.

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

The callback status check matters: do not treat a file rendered after a failed open as a valid capture. The official quick start checks the status and exits after rendering; PhantomJS otherwise continues running. This example uses a nonzero exit status on failure so a calling script can detect the error.

Choose the framing: viewport or crop

Capture the page without a crop

Without clipRect, page.render() processes the entire page. The viewport still determines the page’s layout, so a mobile-width viewport may produce a different arrangement than a desktop-width one. Decide on the intended responsive composition first, then set both viewport dimensions before opening the URL. See the PhantomJS screen-capture guide.

Capture a specific rectangle

Set clipRect before rendering when you need a defined area rather than the uncropped page:

page.clipRect = { top: 0, left: 0, width: 900, height: 700 };
page.render('capture.png');

The rectangle is measured from the top-left position specified by top and left, and uses the given width and height. Confirm that the rectangle includes the content you need; otherwise the result will be cropped too tightly. The clipRect reference documents the property.

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

Choose an output format and quality setting

The documented page.render() formats include PDF, PNG, JPEG, BMP, PPM, and GIF; GIF support depends on the Qt build. Pick the format for the job rather than treating its quality parameter as a general sharpness control.

Format When it fits What the quality setting means
PNG Interface screenshots where crisp text and edges matter. Quality changes lossless Deflate compression and file size, not the image’s appearance.
JPEG Photographic content or cases where a smaller file is useful. Quality trades visual fidelity against file size. The documented range is integer 0–100, with a default of 75; JPEG output uses 2×2 subsampling.
PDF A document-style capture when a PDF output is needed. The API’s quality parameter only affects JPEG and PNG.
BMP, PPM, GIF Use when a downstream workflow specifically needs one of these formats. Do not assume GIF is available in every Qt build.

For example, a JPEG render can specify its quality in the render options:

page.render('capture.jpg', { format: 'jpeg', quality: 90 });

The value 90 here is an example choice, not a guarantee of a particular file size or visual result. Increase JPEG quality when artifacts are distracting, and reduce it if file size matters more. For PNG, raising quality can make the file larger without making the image look sharper. Consult the official render API for format and quality behavior.

Wait for content that appears after page load

The page-open callback tells you that PhantomJS completed its open operation, but asynchronous page content may still need time to appear. The official viewport example illustrates waiting briefly after a successful open; a fixed delay is only an example and is not a universal readiness guarantee.

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

If the target page has a known, page-specific signal that content is ready, base your capture timing on that signal where your page and PhantomJS setup support it. The documentation covered here does not establish a general-purpose modern readiness mechanism, so do not assume that a particular delay or network condition works for every site. For a simple page that benefits from a short settling period, the callback can use a timer:

page.open('https://example.com/', function (status) {
  if (status !== 'success') {
    console.log('Unable to load the address!');
    phantom.exit(1);
    return;
  }

  window.setTimeout(function () {
    page.render('capture.png');
    phantom.exit();
  }, 1000);
});

The one-second wait is deliberately just an example. A page that loads content later may still be incomplete; a static page may need no extra wait. Prefer a readiness condition tied to the content you require over increasing a blind delay, when a suitable condition is available.

Improve the result with a repeatable checklist

  • Match the intended layout: set the desired viewport width and height before opening the page.
  • Check that opening succeeded: branch on the callback’s status and stop on failure.
  • Wait for the important content: use a page-specific readiness check where possible; treat a fixed delay as a site-dependent fallback.
  • Choose framing deliberately: omit clipRect for the uncropped page, or define a rectangle that includes the required content.
  • Choose the right file type: use PNG for lossless interface detail or JPEG when its lossy size-versus-quality tradeoff suits the image.
  • Exit after capture: call phantom.exit() after the render so the process does not continue running.

Troubleshoot common capture problems

The output is blank or the page did not load

Check the open callback status before rendering. If it is not success, the example reports a load failure and exits rather than presenting the output as a good screenshot. Verify the target address and the environment’s ability to open it, then rerun.

The page uses the wrong responsive layout

Set page.viewportSize before page.open(), and choose both dimensions to match the layout you want. Changing the viewport is not just a crop: it can cause the page itself to rearrange.

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

Content is missing from an otherwise successful capture

The page may render content asynchronously after the open callback. Add an appropriate wait or a page-specific readiness check before rendering. A fixed delay can help on one page but is not proof that all required content has appeared.

The screenshot cuts off content

Inspect whether clipRect is set. Its rectangle deliberately limits the rendered region; adjust its position and dimensions or omit it for an uncropped render.

The PNG looks no sharper after changing quality

That is expected: PNG quality controls lossless compression and file size, not visual appearance. If a JPEG looks degraded, adjust its quality value within the documented 0–100 range and compare the resulting file size.

The PhantomJS process does not finish

Ensure every success and failure path ends with phantom.exit(). In the delayed example, the exit occurs inside the timer after rendering; a failure exits directly from the callback.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Compatibility and reliability limits

The PhantomJS pages cited here document its API and examples, but they do not establish current maintenance status, present-day operating-system support, or compatibility with modern JavaScript and websites. Treat the code as a documented PhantomJS workflow, not a promise that every current site will render correctly. Validate your actual target pages, output format, and runtime environment before building an important capture process around it.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. Instead of configuring a PhantomJS browser process, make a GET request with the target URL. The following cURL request saves a WebP screenshot of Stripe; replace the URL with the page you need. See the ScreenshotNeo documentation for the API options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and each response reports the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

The free plan includes 1,000 screenshots a month with no card. Paid plans start at $5 for 3,000 screenshots; every feature is available on every plan. Sign up free for 1,000 screenshots a month, with no card required.

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

Frequently Asked Questions

Can PhantomJS capture a region instead of the whole page?

Yes. Set page.clipRect before page.render() to define the rectangle to render.

Does the PhantomJS documentation establish support for current websites?

No. It documents the capture API, but does not establish compatibility with current sites or systems. Test the pages and runtime you plan to use.

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.