October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Capture a Website Screenshot with PhantomJS After JavaScript Loads

Use PhantomJS’s webpage module to verify a page load, wait for JavaScript-rendered content, and render a screenshot only when the content is ready.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use PhantomJS’s webpage module to open the URL, check that loading succeeded, wait for the specific JavaScript-rendered content your page needs, and then call page.render(). The page.open() callback is a useful first readiness check, but it does not guarantee every asynchronous update, widget, or animation has finished.

Capture after the page’s JavaScript has rendered

Save this as capture.js and run it with PhantomJS, passing the page URL as the first argument:

var page = require('webpage').create();
var system = require('system');
var address = system.args[1];

page.viewportSize = { width: 1280, height: 800 };

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

  // If the target app renders important content asynchronously,
  // wait for that page-specific condition before rendering.
  page.render('capture.png');
  phantom.exit();
});

For example: phantomjs capture.js https://example.com. The script sets the viewport before opening the URL, checks the load status, writes a PNG, and exits. PhantomJS’s quick start demonstrates this basic page.open() and page.render() workflow.

Choose a readiness signal that matches the page

When the load callback is enough

If the required content is present when document loading finishes, render inside the successful page.open() callback. The callback receives a success or failure status when the load finishes; it is not a general signal that all application-specific work has settled. See the page.open API.

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

For content populated after load

Wait for a known page condition, such as a populated #results element, before rendering. page.evaluate() runs in the page context, where it can inspect ordinary DOM properties. Keep the polling timer and maximum wait in the outer PhantomJS script so the capture has a clear deadline and can report a timeout instead of silently saving an incomplete image.

var page = require('webpage').create();
var system = require('system');
var address = system.args[1];
var selector = '#results';
var deadline;
var poll;
var finished = false;

page.viewportSize = { width: 1280, height: 800 };

function stopWithError(message) {
  if (finished) return;
  finished = true;
  clearInterval(poll);
  clearTimeout(deadline);
  console.log(message);
  phantom.exit(1);
}

page.open(address, function (status) {
  if (status !== 'success') {
    stopWithError('Unable to load ' + address);
    return;
  }

  function isReady() {
    return page.evaluate(function (sel) {
      var element = document.querySelector(sel);
      return !!element && element.textContent.trim().length > 0;
    }, selector);
  }

  function captureIfReady() {
    if (finished || !isReady()) return;
    finished = true;
    clearInterval(poll);
    clearTimeout(deadline);
    page.render('capture.png');
    phantom.exit();
  }

  deadline = setTimeout(function () {
    stopWithError('Timed out waiting for ' + selector);
  }, 15000);

  poll = setInterval(captureIfReady, 250);
  captureIfReady();
});

Replace #results with a selector and condition that actually indicate usable content on the target site. A node merely existing may not be enough if it is still empty or loading. The 15-second deadline and 250-millisecond polling interval are example choices, not universal values; tune them to the page and your own latency requirements.

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

For a known delay

If the page updates on a predictable timer and has no dependable DOM condition, schedule the render after a bounded delay following a successful load. A delay is a practical fallback, not proof that every request or animation has completed. Prefer a page-specific condition when possible.

Configure viewport, crop, format, and loading behavior

Viewport and crop

Set page.viewportSize before opening the URL to define the browser viewport used for rendering. Use page.clipRect when you want a particular rectangular region. The screen-capture guide covers viewport and clipping controls. A clip rectangle selects an area; it does not automatically include all content below the fold.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
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.

Output formats and image quality

page.render(filename) uses the filename extension to select an output format. The render API lists PDF, PNG, JPEG, BMP, PPM, and GIF where supported by the build. Choose PNG when you want lossless image output, JPEG when lossy compression is acceptable, or PDF for document-oriented output. The render quality option affects JPEG quality; for PNG it changes lossless Deflate compression and can alter file size without changing the image pixels.

JavaScript, images, and resource timeout

In the documented webpage settings, JavaScript and image loading are enabled by default. You can set page.settings.resourceTimeout in milliseconds before the initial page.open() if you need a bound on resource loading. The settings reference notes that these settings apply during that initial open call. A resource timeout is not the same as a guarantee that application logic has finished; consult the settings API.

Rank #4
Sale
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

Handle failures and incomplete captures

  • The script reports a failed load: Check the URL and network access, and handle the non-success status instead of rendering a presumed-valid page.
  • The screenshot is blank or missing expected text: Check whether the readiness selector exists and is populated, whether JavaScript is enabled, and whether resources failed or timed out. A successful load callback alone does not prove the application has finished rendering.
  • Content is cut off: Verify the viewport dimensions and whether you intended to capture the viewport or a specific clip rectangle. Do not treat clipping as a full-page capture setting.
  • The process exits before output is written: Call phantom.exit() only after rendering or other asynchronous work is complete. The automation guide illustrates this ordering by exiting inside the page.includeJs() callback.
  • A modern site still renders incorrectly: PhantomJS uses an older WebKit-based workflow. The cited API references do not establish compatibility with any particular current framework or browser feature, so validate the actual target page rather than assuming modern-site support.
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 offers a website screenshot API, so you can request a capture without managing a PhantomJS process. The call below saves a WebP response; see the ScreenshotNeo documentation for 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 removes cookie banners, newsletter popups, and chat widgets before capture; those cleanup steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides screenshot tools for AI agents, and 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 with no card.

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

Frequently asked questions

Can I use this approach to capture a PDF?

Yes. Render to a filename with a .pdf extension if the PhantomJS build supports PDF output; the render API lists PDF among its supported formats.

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.

Does the script capture the entire page?

The example sets a viewport and renders a screenshot, while clipRect controls a specific region. Neither setting by itself guarantees a complete below-the-fold capture; choose dimensions and capture behavior for the output you need.

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 *

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
PC Slower Than It Used to Be?Free scan - under a minute
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.