Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
Developer Tools

How to Take a Website Screenshot at Runtime with PhantomJS

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

Use PhantomJS’s webpage module, set the viewport before navigation, wait for the page’s real readiness signal, then call page.render() and exit only after rendering completes. The essential sequence is:

  1. Create a page.
  2. Set viewportSize (and, when needed, clipRect).
  3. Open the URL and verify the callback status.
  4. Wait for dynamic content.
  5. Render to PNG, JPEG, WebP-compatible alternatives, or PDF supported by your build.
  6. Call phantom.exit().

PhantomJS is legacy software: its project says development is suspended until further notice. Validate it against your target sites before putting it into a new production system.

Minimal runtime screenshot script

Save this as screenshot.js and run it with the PhantomJS executable:

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

page.viewportSize = { width: 1024, height: 768 };

page.open('https://example.com', function (status) {
  console.log('Status: ' + status);
  if (status === 'success') {
    page.render('example.png');
  }
  phantom.exit();
});

The viewport must be configured before page.open(). It controls responsive breakpoints and the dimensions of the rendered browser surface. Check the callback’s status; rendering after a failed open usually produces a blank or incomplete file.

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.
#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Install and run PhantomJS safely

Use an existing, compatible build

PhantomJS binaries and packaging vary by operating system. Because development is suspended, first check that the binary runs on your OS and that its WebKit engine can execute the JavaScript and CSS used by your site. Confirm the version in your deployment image, rather than assuming a current browser is represented.

Execute the script

phantomjs screenshot.js

Use an absolute output path when a scheduler or service may start in a different working directory:

page.render('/var/tmp/captures/example.png');

Ensure the PhantomJS process can write to that directory and that the parent directory already exists.

Wait until the page is actually ready

page.open() is the first readiness checkpoint, not proof that every image, widget, or late network request has finished. A short bounded delay can help pages that render immediately after navigation:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
var page = require('webpage').create();
page.viewportSize = { width: 1024, height: 768 };

page.open('https://example.com/dashboard', function (status) {
  if (status !== 'success') {
    console.log('Open failed: ' + status);
    phantom.exit();
    return;
  }

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

A fixed delay is only a fallback. Prefer a page-specific signal that your application controls. The following pattern polls for an element and stops at a deadline:

var page = require('webpage').create();
page.viewportSize = { width: 1280, height: 900 };

var url = 'https://example.com/app';
var output = 'app.png';
var started = Date.now();
var timeoutMs = 15000;

function finish(status) {
  if (status === 'success') {
    page.render(output);
  } else {
    console.log('Navigation status: ' + status);
  }
  phantom.exit();
}

function waitForReady() {
  var ready = page.evaluate(function () {
    return !!document.querySelector('[data-screenshot-ready="true"]');
  });

  if (ready || Date.now() - started >= timeoutMs) {
    finish('success');
    return;
  }
  window.setTimeout(waitForReady, 250);
}

page.open(url, function (status) {
  if (status !== 'success') {
    finish(status);
    return;
  }
  waitForReady();
});

Use a bounded wait so a missing selector cannot leave a worker running forever. If the page never exposes a reliable signal, choose a delay based on its known behavior and record that trade-off.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Set the viewport and capture a region

Viewport dimensions

PhantomJS defaults to a 400×300 viewport. Set it explicitly for reproducible output:

page.viewportSize = { width: 1440, height: 900 };

Changing these values can change navigation menus, column counts, font wrapping, and lazy-loading behavior.

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

Rectangular clipping

Use clipRect when you need a fixed rectangle rather than the whole viewport:

page.viewportSize = { width: 1024, height: 768 };
page.clipRect = { top: 80, left: 120, width: 640, height: 420 };

The rectangle is measured in page pixels. Keep it inside the intended viewport and account for sticky headers when choosing top.

Element-focused captures

PhantomJS’s core API exposes a rectangle, not a CSS-selector capture primitive. Measure an element in the page and assign its bounds:

var rect = page.evaluate(function () {
  var node = document.querySelector('#invoice');
  if (!node) return null;
  var r = node.getBoundingClientRect();
  return { top: r.top, left: r.left, width: r.width, height: r.height };
});

if (rect) {
  page.clipRect = rect;
  page.render('invoice.png');
}

For pages that scroll, add the current scroll offset to the rectangle’s coordinates, and wait until fonts and images are loaded before measuring.

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

Choose an output format and quality

page.render(filename) normally infers the format from the extension. PhantomJS builds commonly support PDF, PNG, JPEG, BMP, PPM, and GIF when the Qt build includes GIF support:

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.
page.render('page.png');
page.render('page.jpg', { format: 'jpg', quality: 85 });
page.render('page.pdf');

JPEG quality is an integer from 0 to 100 and changes compression. PNG quality changes Deflate compression, not the rendered pixels. A PDF is useful for print-oriented output, but verify pagination and fonts in the specific PhantomJS build you deploy.

Settings that affect fidelity and access

Set page settings before page.open(); they apply during the initial navigation:

var page = require('webpage').create();
page.settings.javascriptEnabled = true;
page.settings.loadImages = true;
page.settings.userAgent = 'Mozilla/5.0 (compatible; RuntimeCapture/1.0)';
page.settings.resourceTimeout = 15000;
page.viewportSize = { width: 1024, height: 768 };
  • javascriptEnabled: enabled by default; disabling it removes client-side rendering and can make an application appear empty.
  • loadImages: enabled by default; turn it off only when speed matters more than visual completeness.
  • userAgent: some servers deliver different markup to different agents. Use a truthful value and test the resulting layout.
  • resourceTimeout: bounds individual resource loading so one stalled request does not wait forever.

Authentication, modern TLS behavior, Web APIs, and bot defenses may exceed PhantomJS’s older browser engine. Do not treat a successful HTTP navigation as proof that protected content was captured.

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

Full-page captures versus viewport captures

A normal page.render() reflects the configured viewport. A long document may therefore produce only the visible area, depending on the PhantomJS build and rendering path. For a full-page result, measure the document and enlarge the viewport before rendering:

var size = page.evaluate(function () {
  return {
    width: Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
    height: Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)
  };
});

page.viewportSize = { width: 1024, height: size.height };
page.clipRect = { top: 0, left: 0, width: size.width, height: size.height };
page.render('full-page.png');

Very tall pages can consume substantial memory. For reports, PDF pagination or multiple viewport-sized captures may be more reliable than one enormous bitmap.

Make captures reproducible

  • Pin the PhantomJS binary and record its version.
  • Set viewport, user agent, image loading, and timeout explicitly.
  • Use deterministic test data and a fixed URL, including query parameters that select the desired state.
  • Wait for a DOM readiness marker rather than guessing when an animation ends.
  • Disable or account for rotating carousels, timestamps, ads, and personalized content.
  • Write unique filenames and preserve the navigation status in logs.

Rendering is single-process work in many deployments. For throughput, run a controlled pool of workers, cap concurrent pages, and monitor memory; increasing concurrency without limits can make failures look like network problems.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common failures

The image is blank

Log the callback status and verify the URL from the same machine. A failed navigation, JavaScript exception, unsupported TLS setup, or an overly narrow clip rectangle can all yield an apparently blank file. Temporarily remove clipRect, keep javascriptEnabled and loadImages enabled, and capture the viewport first.

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

The screenshot is taken too early

Wait for a page-owned selector or a bounded delay. A successful page.open() callback can occur before asynchronous API data, images, or fonts finish. Do not call phantom.exit() until the render call has returned.

Modern layout is missing

PhantomJS uses an old WebKit engine. Unsupported CSS, JavaScript syntax, browser APIs, or TLS can prevent a faithful result. Simplify the target page for this legacy renderer or use a maintained browser-based service.

Images or fonts are absent

Confirm loadImages is true, inspect resource failures, and extend resourceTimeout for slow assets. Cross-origin restrictions and authentication can still prevent loading even when the main document succeeds.

Only part of the page appears

Check viewportSize, clipRect, and document dimensions. A clip rectangle intentionally limits output; a default 400×300 viewport can also make a capture look unexpectedly small.

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

The process never terminates

Use a timeout around readiness polling and call phantom.exit() on every success and failure branch. Do not leave timers or callbacks running after the render completes.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Or skip the browser setup

ScreenshotNeo provides a hosted website screenshot API when maintaining a legacy browser is not practical. A GET request returns a PNG, JPEG, WebP, or PDF:

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

See the ScreenshotNeo documentation for all parameters. The equivalent Python and Node.js calls are:

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)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Before capture, it accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server lets Claude, Cursor, and other MCP clients use take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

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

When PhantomJS is still a reasonable choice

PhantomJS can remain useful for a pinned, known-compatible internal page where its small script and deterministic viewport are valuable. It is a poor default for sites that require current browser APIs, modern CSS, interactive authentication, or active maintenance. Compare maintenance status, JavaScript and CSS compatibility, clipping and full-page behavior, output formats, startup cost, and authentication requirements before standardizing on it.

Frequently Asked Questions

Does PhantomJS wait for network idle automatically?

No. The page.open() callback is only an initial checkpoint. Use a page-specific DOM signal or a bounded delay for late content.

What is PhantomJS’s default viewport?

CasperJS documentation records a default viewport of 400×300. Set page.viewportSize explicitly for reproducible captures.

Can PhantomJS capture a PDF?

Yes, page.render() can write PDF when the build supports it; use a .pdf filename and verify pagination in your environment.

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

Is PhantomJS actively maintained?

No. The official project homepage states that development is suspended until further notice, so test compatibility carefully before new adoption.

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.

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.

Read next

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

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.