Recommended Free Tools
Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
To hide routine messages from a page loaded by PhantomJS, remove the page.onConsoleMessage handler that forwards them to console.log, or keep the handler and print only messages you explicitly want. PhantomJS does not display webpage console messages by default. Messages written by console.log in your PhantomJS script are a separate source and must be removed or guarded independently.
First identify which code is producing the output
A PhantomJS terminal can contain output from two different places. The fix depends on which one you are seeing.
| Source | Typical code | How to hide it |
|---|---|---|
| Your PhantomJS script | console.log('starting'); |
Delete the call or place it behind a condition. |
| The loaded webpage | Page JavaScript calling console.log, console.warn or similar |
Do not install a forwarding page.onConsoleMessage callback, or make that callback filter messages without printing them. |
| Page JavaScript exceptions | Errors reported through page.onError |
Keep or adjust page.onError separately if you still need diagnostics. |
The official onConsoleMessage documentation says that console messages from the webpage are not displayed by default. The Quick Start likewise shows that terminal output comes from the PhantomJS script’s own console.log, while messages generated inside the loaded page remain silent unless you redirect them.
Remove the forwarding callback to restore silent page logs
A common debugging snippet looks like this:
page.onConsoleMessage = function (msg) {
console.log(msg);
};
That callback takes a message generated by the loaded page and writes it with the PhantomJS script’s console.log. Delete it, comment it out, or never assign it:
#1 Best Overall
var page = require('webpage').create();
// No page.onConsoleMessage assignment.
// Webpage console messages are not printed by PhantomJS by default.
page.open('https://example.com', function (status) {
if (status !== 'success') {
console.log('Page failed to load');
phantom.exit(1);
return;
}
console.log('Page loaded');
phantom.exit();
});
This suppresses routine console output from the site, but it does not suppress the Page loaded line: that line is generated by your script. Remove that line too if you want a completely quiet successful run.
Keep diagnostics while hiding normal messages
Use page.onError for page JavaScript exceptions when you need stack information. The PhantomJS Troubleshooting guide demonstrates this separate error callback. A quiet logging setup can therefore look like:
var page = require('webpage').create();
// Deliberately no page.onConsoleMessage handler.
page.onError = function (message, trace) {
console.error('Page error: ' + message);
trace.forEach(function (item) {
console.error(' at ' + item.file + ':' + item.line);
});
};
page.open('https://example.com', function (status) {
if (status !== 'success') {
console.error('Unable to open page');
phantom.exit(1);
return;
}
phantom.exit();
});
Here, ordinary page console calls are not relayed, while exceptions still produce a message and trace. If your script itself must remain silent on success, remove or condition the two status messages as well.
Filter page messages instead of hiding all of them
If a site emits one useful diagnostic among many noisy messages, keep onConsoleMessage and gate the output. The callback receives the page message; only the branch that calls the script’s console.log reaches the terminal.
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
var page = require('webpage').create();
page.onConsoleMessage = function (msg) {
if (msg.indexOf('keep:') === 0) {
console.log(msg);
}
};
page.open('https://example.com', function (status) {
if (status !== 'success') {
console.error('Unable to open page');
phantom.exit(1);
return;
}
phantom.exit();
});
For example, a page message beginning with keep: is printed, while every other page message is discarded. A callback that performs no printing at all is also valid:
page.onConsoleMessage = function (msg) {
// Intentionally ignore page console output.
};
Do not confuse filtering with changing the webpage’s JavaScript. The callback controls what PhantomJS relays to its terminal; the page still runs its own code.
Silence PhantomJS script logging
When the noisy line is in your own .js file, onConsoleMessage is irrelevant. Search the PhantomJS script for console.log, console.warn and console.error. Remove routine calls or guard them with a flag:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minutevar verbose = false;
function log(message) {
if (verbose) {
console.log(message);
}
}
log('navigation started');
Run with verbose enabled only while diagnosing a failure. Keep an error path if an unattended job needs a nonzero exit status or an explanation for a failed load.
Rank #3
A complete quiet-by-default script
The following example hides page console messages, makes script logging opt-in, and retains page exception traces:
var page = require('webpage').create();
var verbose = false;
function info(message) {
if (verbose) {
console.log(message);
}
}
// No onConsoleMessage handler: page console output stays hidden.
page.onError = function (message, trace) {
console.error('Page exception: ' + message);
trace.forEach(function (item) {
console.error(' at ' + item.file + ':' + item.line);
});
};
page.open('https://example.com', function (status) {
if (status !== 'success') {
console.error('Page failed to load');
phantom.exit(1);
return;
}
info('Page loaded');
phantom.exit(0);
});
Save it as quiet.js and run phantomjs quiet.js. A successful run produces no output when verbose is false. A page exception or failed open still reports an error.
Troubleshoot output that remains
The terminal still shows ordinary page messages
- Search for every assignment to
page.onConsoleMessage, including code in helper modules. One handler elsewhere may still callconsole.log. - Confirm that the line is not generated by your own script. Add a temporary prefix such as
HOST:to your script logs; page messages can then be distinguished while you locate the source. - Check whether a wrapper, shell script or test runner is printing captured output after PhantomJS exits. That output is outside the WebPage callback.
Errors disappeared along with the noise
Do not replace page.onError with onConsoleMessage. They serve different purposes. Restore an onError handler if you need page exception messages and stack traces, while leaving routine console forwarding disabled.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →console.error behaves differently from console.log
A 2017 archived issue reports different handling of console.error in two PhantomJS 2.1.1 binaries distributed for Ubuntu and Debian. Treat that as build-specific evidence, not a guarantee for every executable. Record the exact binary and distribution you run, then test the behavior with a minimal page if routing of error-level messages matters: the issue report.
Rank #4
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Removing the callback did not quiet a fork or another browser
The documented default applies to PhantomJS’s WebPage API. Forks and unrelated headless-browser tools may implement console routing differently. Verify that the command is invoking the PhantomJS executable you expect and inspect that implementation’s documentation before applying this pattern.
Version and maintenance considerations
PhantomJS is legacy software. The project wiki describes the 2.x branch as deprecated and no longer maintained, and the GitHub repository is archived: PhantomJS project wiki. This article’s callback behavior is therefore specific to the PhantomJS WebPage API, not a recommendation to start a new automation system on PhantomJS. If you must keep an existing job running, pin and document its executable or package build so a distribution change does not silently alter console routing.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If your actual goal is a clean image or PDF of a URL rather than maintaining a PhantomJS capture script, ScreenshotNeo provides a single HTTP request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and response headers identify the page verdict and billing status.
Free tools Windows power users keep installed
One-click scans. No signup required.
Use the API endpoint documented at ScreenshotNeo’s documentation:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The same request in Python:
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
And in Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));
ScreenshotNeo also exposes an MCP server with take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients. Beyond basic screenshots, its 63 options include full-page lazy-image loading, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF paper and margin controls, custom CSS and JavaScript, pre-capture clicks, selector or network-idle waits, request and resource blocking, headers, cookies, user-agent, authorization, timezone, geolocation, transparent backgrounds, resizing, selectable cache TTLs, signed image links, asynchronous webhooks, bulk capture for up to 100 URLs per call, a usage API and an OpenAPI specification. Parameter names used by other screenshot APIs are accepted to ease migration.
Best Value
The Free plan includes 1,000 shots each month without a card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free, and every feature is available on every plan. Create a free ScreenshotNeo account to try it.
Practical decision checklist
- If the line is from
console.login your PhantomJS file, remove or guard that call. - If it is a webpage message, remove the forwarding
page.onConsoleMessageassignment. - If you need selected diagnostics, filter the callback and print only an agreed prefix.
- Keep
page.onErrorwhen page exceptions and traces are still important. - When
console.errorrouting is inconsistent, verify the exact PhantomJS 2.1.1 build or package.
Frequently Asked Questions
Will deleting page.onConsoleMessage stop JavaScript errors on the page?
No. It stops the callback that relays console messages. Page exceptions can still be captured independently with page.onError.
Can I hide only warnings while keeping errors?
Use a filtering onConsoleMessage callback and match the message text or prefix your page emits. PhantomJS does not provide a documented severity argument in this callback, so your filter must use the message content.
Why does a clean PhantomJS run still print something?
The remaining text is likely from a script-level log, an onError handler, a failed page-open branch, or a wrapper process. Trace the line to its producer rather than muting every diagnostic.
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.

