An empty PhantomJS or CasperJS screenshot usually means the capture happened before the page reached the state you expected, the target was outside the viewport, a script or request failed, or the image is transparent rather than blank. Diagnose those layers in order: verify the navigation result and required DOM, wait for a meaningful condition, set and apply an explicit viewport, log requests and JavaScript errors, then inspect the output alpha channel and PhantomJS binary.
Start with evidence, not a longer delay
Opening a URL only proves that navigation was attempted. It does not prove that an application has rendered its data, that an image finished loading, or that the selector you intend to capture exists. CasperJS documentation describes intermittent failures caused by tests running before a resource or element is available and recommends waiting for nodes, text, visible selectors, or resources.
Make the script report each stage:
- the navigation status returned by
open(); - whether the required text or selector exists;
- the viewport in effect at capture time;
- resource requests and failures;
- page-side JavaScript exceptions; and
- the saved file’s dimensions and alpha behavior.
This evidence separates readiness, geometry, execution, transport, and output-appearance problems instead of treating every empty image as the same bug.
A reliable diagnostic sequence
1. Confirm the page and intended content
Use a condition tied to the screenshot state. For a product page, that might be a product title; for a dashboard, a chart container; for an article, the headline and an image. A fixed sleep is useful as a temporary experiment, but there is no universal safe delay because site and network timing vary.
#1 Best Overall
- 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
var page = require('webpage').create();
page.open('https://example.com/dashboard', function (status) {
console.log('navigation status: ' + status);
console.log('title: ' + page.evaluate(function () { return document.title; }));
console.log('has chart: ' + page.evaluate(function () {
return !!document.querySelector('[data-chart-ready]');
}));
phantom.exit(status === 'success' ? 0 : 1);
});
A successful navigation status with has chart: false is a readiness problem, not proof that rendering is broken.
2. Wait for a real readiness condition in CasperJS
CasperJS exposes waitForText, waitForSelector, visible-selector waits, and resource waits. Use the narrowest condition that represents the desired screenshot, and make timeout behavior visible.
var casper = require('casper').create({
verbose: true,
logLevel: 'debug'
});
casper.start('https://example.com/dashboard', function () {
this.viewport(1366, 900);
});
casper.waitForSelector('[data-chart-ready]', function () {
this.echo('chart is ready');
}, function () {
this.die('chart did not become ready before timeout', 1);
});
casper.then(function () {
this.capture('dashboard.png');
});
casper.run(function () {
this.exit();
});
If you need text rather than a selector, replace the wait with waitForText('Expected heading', success, failure). A temporary wait(3000) can show whether timing is involved, but replace it with a condition before relying on the script.
3. Set the viewport before capture
PhantomJS ships with a 400×300 default viewport, and CasperJS does not override it by default. That small canvas can trigger responsive layouts, hide navigation, or place your target below the fold. Set the intended width and height explicitly. CasperJS applies viewport changes asynchronously, so perform the change before the readiness wait and capture in later steps.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #2
- 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
casper.start('https://example.com', function () {
this.viewport(1440, 1000);
});
casper.then(function () {
this.captureSelector('hero.png', '.hero');
});
For a full-page capture, use CasperJS’s whole-page capture method; for a component, use selector capture. Before selector capture, verify that the selector exists and is visible. A selector that matches nothing can produce an apparently empty result even when the document itself rendered correctly.
4. Log requests and JavaScript errors
PhantomJS troubleshooting guidance recommends logging requested resources and registering a page onError handler. Together they show whether a stylesheet, script, image, or API call was requested and whether an exception stopped the page’s rendering code.
var page = require('webpage').create();
page.onResourceRequested = function (request) {
console.log('request: ' + request.method + ' ' + request.url);
};
page.onResourceError = function (error) {
console.log('resource error: ' + error.errorCode + ' ' + error.errorString +
' ' + error.url);
};
page.onError = function (message, trace) {
console.log('page error: ' + message);
trace.forEach(function (frame) {
console.log(' ' + frame.file + ':' + frame.line +
(frame.function ? ' in ' + frame.function : ''));
});
};
page.open('https://example.com', function (status) {
console.log('status: ' + status);
page.render('out.png');
phantom.exit();
});
If HTTP succeeds but HTTPS does not, check the SSL libraries available to the PhantomJS build, as the troubleshooting guide advises. A failed API request or an exception in application JavaScript can leave a valid document shell with no visible content; these logs distinguish that from a capture-order mistake.
5. Check whether “blank” means transparent
PhantomJS does not impose a page background color. If the page leaves its background unset, the rendered image can have a transparent background and appear white, black, or empty depending on the viewer. Inspect the PNG in a transparency-aware editor or examine its alpha channel. If an opaque image is required, set a background before rendering:
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Rank #3
- 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.evaluate(function () {
document.documentElement.style.backgroundColor = '#ffffff';
document.body.style.backgroundColor = '#ffffff';
});
page.render('opaque.png');
Do this after the page has loaded and before capture. If the page intentionally uses transparency, preserve the alpha channel and verify the file against a contrasting background instead of changing the design.
PhantomJS and CasperJS capture patterns
Minimal PhantomJS script with readiness polling
var system = require('system');
var page = require('webpage').create();
page.viewportSize = { width: 1366, height: 900 };
page.onError = function (message, trace) {
console.log('JS error: ' + message);
};
page.onResourceError = function (error) {
console.log('Resource error: ' + error.url + ' — ' + error.errorString);
};
page.open(system.args[1], function (status) {
if (status !== 'success') {
console.log('open failed: ' + status);
phantom.exit(1);
return;
}
var deadline = Date.now() + 15000;
var timer = setInterval(function () {
var ready = page.evaluate(function () {
return !!document.querySelector('[data-screenshot-ready]');
});
if (ready) {
page.evaluate(function () {
document.body.style.backgroundColor = '#fff';
});
page.render('shot.png');
clearInterval(timer);
phantom.exit(0);
} else if (Date.now() > deadline) {
console.log('readiness timeout');
clearInterval(timer);
phantom.exit(2);
}
}, 100);
});
Run it as phantomjs capture.js https://example.com. Replace the readiness selector with one owned by the page. The explicit exit codes make a CI job fail for navigation or readiness errors instead of publishing an empty artifact.
CasperJS selector and full-page captures
var casper = require('casper').create({ logLevel: 'debug' });
casper.start('https://example.com/report', function () {
this.viewport(1600, 1000);
});
casper.waitForSelector('#report-complete', function () {
if (!this.exists('#report')) {
this.die('#report is missing', 1);
}
this.captureSelector('report.png', '#report');
}, function () {
this.die('report-complete did not appear', 1);
});
casper.run(function () { this.exit(); });
Use a full-page capture when the content extends below the viewport; use a selector capture when you need only a component. In both cases, capture only after the condition that proves the content is present.
Use the failure layer to choose the next check
| Observed evidence | Likely layer | Next action |
|---|---|---|
| Navigation succeeds, required selector is absent | Readiness | Wait for the selector, text, or resource that represents the final state. |
| Target exists but is clipped or missing | Geometry | Set an explicit viewport, wait for it to apply, and verify selector visibility. |
| Console output shows an exception | Page execution | Fix the failing script or provide the dependency it expects. |
| Requests fail, especially over HTTPS | Transport | Inspect resource errors and SSL libraries; confirm the URL works in the same environment. |
| Pixels are empty in one viewer but alpha is zero | Output appearance | Set an opaque background or view the image over a contrasting layer. |
These categories are practical diagnostic groupings, not a guarantee that one symptom has only one cause. Record the actual status, logs, viewport, and alpha result before declaring a fix.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsRank #4
- 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
Remote debugging and binary verification
When logs do not explain the result, start PhantomJS with its documented --remote-debugger-port option and inspect the page in the remote debugger. This lets you examine the live DOM and JavaScript state at the point of failure.
Also verify which executable is running. On hosts with multiple installations, print the PhantomJS version and inspect the path used by your job. A script edited for one binary can silently run under another, with different SSL support or rendering behavior.
Reliability and performance practices
- Wait for the smallest meaningful condition rather than an unnecessarily long fixed sleep.
- Keep a diagnostic mode that logs requests and page errors; turn verbose output down only after the capture is stable.
- Use a bounded timeout and nonzero exit code for missing content, so automation cannot mistake an empty file for success.
- Reuse a consistent viewport in CI and local runs when comparing images.
- Capture only the required selector when a full page is not needed; it reduces output size and makes visual diffs easier to interpret.
- Retain the failing URL, status, viewport, and logs with the image artifact. Timing-sensitive failures are otherwise difficult to reproduce.
PhantomJS and CasperJS documentation describes APIs and behavior, not compatibility with every modern website. Reproduce the specific URL in the same network and runtime environment before attributing the failure to a single cause.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server for developers. It accepts a URL and returns PNG, JPEG, WebP, or PDF. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and whether it was billed.
One GET request is enough:
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 authentication and options. The equivalent Python and Node.js calls are:
Best Value
- 【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.
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}`);
ScreenshotNeo includes full-page and CSS-selector captures, lazy-image loading, dark mode, 12 device presets plus custom viewports, retina scale, PDF paper and page-range controls, custom CSS and JavaScript, pre-capture clicks, hidden selectors, waits for selectors, delays or network idle, request and resource blocking, headers, cookies, user agents, Authorization, timezone and geolocation, transparent backgrounds, resizing, configurable-TTL caching, signed image links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API, and an OpenAPI specification. Parameter names used by other screenshot APIs also work for easier migration.
An MCP server provides take_screenshot, get_page_info, and capture_pdf tools to Claude, Cursor, and other MCP clients. Every feature is on every plan: 1,000 shots per month free with no card, then Starter is $5 for 3,000, Growth $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000, and Business $249 for 1,000,000; yearly billing gives two months free. Create a free ScreenshotNeo account to try the 1,000 monthly screenshots without a card.
When to replace rather than repair
If the same modern site repeatedly requires workarounds for unsupported JavaScript, TLS, or browser features, document the PhantomJS limitation and move the capture to a maintained browser or an API. Keep the diagnostic sequence: readiness, viewport, requests, errors, and transparency still explain failures in newer engines. The goal is a verified image and a reproducible failure signal, not merely a command that exits successfully.
Frequently Asked Questions
Why does a CasperJS test pass navigation but save a blank file?
Navigation completion and visual readiness are separate events. The page may still be loading data or may have thrown a JavaScript error; wait for the required selector or text and inspect page errors.
Can a 400×300 viewport alone make the screenshot empty?
It can trigger a different responsive layout or put content outside the visible area, but it does not establish the cause by itself. Set the intended viewport and verify the target is present and visible.
How can I tell a transparent PNG from a failed render?
Inspect the alpha channel or view the file over a contrasting background. If the page background was unset, set an explicit background color before capture when an opaque image is required.
Quick Recap
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.
Recommended Free Tools




