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 DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk3 min

How to Capture a Website Screenshot with PhantomJS and Save It as PNG

Open a URL with PhantomJS, check the load status, and save the rendered view with page.render('screenshot.png'). Includes framing and troubleshooting notes for this discontinued tool.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use PhantomJS’s webpage module to open a URL, then call page.render('screenshot.png') from the page-open callback. Save the script as capture.js and run phantomjs capture.js. PhantomJS is discontinued: its homepage says development is suspended, and its GitHub repository has been archived as read-only. Treat this as legacy-maintenance guidance, not a recommended foundation for a new system.

Capture a page and save it as PNG

Create a file named capture.js containing this version, which checks whether the page loaded before writing an image:

# Preview Product Price
1 Responsive Web Design Toolkit Responsive Web Design Toolkit $51.16

As an Amazon Associate I earn from qualifying purchases.

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

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

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

Replace https://example.com/ with the page you want to capture. Run the script through the PhantomJS executable:

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

The string passed to page.render() is the image destination; using the .png extension requests PNG output. The official tutorial’s basic example likewise opens a page, renders a PNG, and exits. See the official screen-capture tutorial and command-line reference.

Set the viewport and capture rectangle

Set page.viewportSize to choose the browser viewport and page.clipRect to select the rectangle rendered into the image. Add these settings before page.open():

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

page.viewportSize = { width: 1024, height: 768 };
page.clipRect = { top: 0, left: 0, width: 1024, height: 768 };

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

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

These settings describe the rendered frame; a viewport-sized capture should not be assumed to include an entire long page. The official tutorial documents PNG, JPEG, GIF, and PDF render formats. For this task, use a PNG filename such as screenshot.png. Details are in the capture documentation.

What to know before maintaining a PhantomJS script

The PhantomJS project homepage states, “Important: PhantomJS development is suspended until further notice.” Its GitHub repository was archived on May 30, 2023 and is read-only. That status matters if you are choosing a tool for new infrastructure: weigh compatibility and security implications rather than assuming current development or binaries for every operating system. The sources cited here do not establish binary availability across current operating systems. Read the project status and archived repository.

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

Troubleshoot failed or unexpected captures

The script reports that PhantomJS is missing or the wrong version

Check which executable is being used with phantomjs --version. The official troubleshooting page notes that multiple installed versions can cause conflicts. The documented CLI form is phantomjs [options] somescript.js [arg1 ...]; the reference is for PhantomJS 2.1.1. See official troubleshooting guidance and the CLI reference.

page.open() returns fail

The callback status is either success or fail. Do not treat an output from a failed load as a valid screenshot; keep the status check and investigate the URL or loading failure. The page.open() API documents the callback status.

The page has a certificate error

The CLI reference lists SSL-related controls, including --ignore-ssl-errors, which changes certificate-error handling. Do not use it as a routine fix: disabling validation can hide a genuine certificate problem. Check the site’s certificate and your runtime configuration first. See the command-line options.

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 website screenshot API and MCP server. Its API can return a PNG, JPEG, WebP, or PDF from one GET request. For example, save this as a PNG 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.png

See the ScreenshotNeo documentation for API details. ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those steps can be switched 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 take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Frequently Asked Questions

Can PhantomJS save a screenshot in formats other than PNG?

Yes. Its screen-capture tutorial lists JPEG, GIF, and PDF as other render formats.

Quick Recap

SaleBestseller No. 1

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 *

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
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.