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

The correct CasperJS method depends on what you mean by “user input.” Use casper.wait() for a known delay, casper.waitFor() for a page condition, and the page.prompt filter for a website’s JavaScript prompt(). None of these is a documented way to stop a running CasperJS script until someone types a line in the terminal. Terminal input requires a controller or process-level design outside CasperJS’s step queue.

Choose the kind of pause first

These requests sound similar but are different runtime problems:

What should release the script? Use Where it runs What happens on failure?
A fixed amount of time casper.wait(milliseconds, callback) CasperJS step queue The next step runs when the timer ends
A page state, such as a selector appearing casper.waitFor(test, then, onTimeout, timeout) CasperJS step queue, checking the page Your timeout callback runs
A JavaScript dialog created by the page page.prompt filter Inside the browser page’s dialog handling Your filter returns a string (or the current value)
A person typing in the shell An external process/controller integration PhantomJS process or a separate controller Defined by your controller; not by a documented CasperJS wait API

CasperJS’s project repository says it is no longer actively maintained, and the API reference is labeled 1.1.0-DEV. Treat examples below as legacy-runtime guidance and check the CasperJS, PhantomJS, or SlimerJS versions actually installed in your environment.

Pause for a fixed delay with wait()

Use a timer only when elapsed time is the requirement—for example, allowing a short animation to finish. The official API describes wait() as pausing step-suite execution for a specified amount of time and optionally running a step when the wait ends.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
var casper = require('casper').create();

casper.start('https://example.com/');

casper.wait(1000, function () {
    this.echo('One second elapsed; continuing.');
});

casper.then(function () {
    this.echo('The following step runs after the wait.');
});

casper.run();

The one-second timer does not observe a human. If the operator needs five minutes, the script still proceeds after one second; if the page is ready sooner, the script still waits. A fixed delay is therefore a poor substitute for both condition-based synchronization and terminal interaction.

Keep the callback small and put subsequent browser actions in later then() steps. This preserves CasperJS’s queued execution model and makes the order visible.

Resume when the page reaches a condition with waitFor()

When the next action depends on dynamic DOM content, wait for a predicate that returns true. The API describes waitFor() as waiting until a function returns true before processing the next step.

var casper = require('casper').create();

casper.start('https://example.com/app');

casper.waitFor(function checkReady() {
    return this.exists('#ready');
}, function ready() {
    this.echo('Ready; continuing.');
}, function timedOut() {
    this.echo('The page did not become ready in time.');
    this.exit();
}, 10000);

casper.then(function () {
    this.click('#continue');
});

casper.run();

How the arguments work

  • test is evaluated repeatedly and must return a boolean.
  • then runs when the test becomes true.
  • onTimeout handles the failure path.
  • timeout is milliseconds. The documented default is 5,000 ms, so choose an explicit value when a page normally needs longer.

For a value rather than a selector, test it directly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
casper.waitFor(function () {
    return this.fetchText('.status').trim() === 'Complete';
}, function () {
    this.echo('The job is complete.');
}, function () {
    this.echo('Status never reached Complete.').exit();
}, 30000);

The documentation notes that waitFor methods are not chainable. If you need to compose one with other actions, add it inside a then() step or place the calls in the queue in the intended order. CasperJS’s FAQ recommends wait* methods when resources or dynamic DOM content may not yet be available, which avoids timing-dependent failures.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Handle a website JavaScript prompt()

A page can call JavaScript such as prompt('What is your name?'). That is not terminal input: it is a browser dialog generated by the page. CasperJS can answer it automatically with the page.prompt filter.

var casper = require('casper').create();

casper.setFilter('page.prompt', function (message, currentValue) {
    if (message === 'What is your name?') {
        return 'Ada';
    }
    return currentValue;
});

casper.start('https://example.com/form');
casper.then(function () {
    this.echo('The page prompt was answered by the filter.');
});
casper.run();

The documented filter signature is message, value (shown as currentValue above), and it returns a string. Match the prompt message narrowly so an unrelated prompt is not answered accidentally. Returning the existing value leaves other prompts unchanged. This is scripted input, so it does not pause and wait for a person to decide what to type.

Can CasperJS wait for terminal input?

There is no documented CasperJS API that suspends an active navigation step until a human enters a line on standard input. wait() and waitFor() are browser-automation queue operations, not blocking shell-read functions. PhantomJS documentation discusses standard streams as inter-process communication, child-process streams, and a REPL that starts without a script argument; those facilities do not establish that a CasperJS script launched with a file automatically inherits interactive REPL behavior.

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

If an operator must approve a step, put that interaction at a process boundary:

Controller pattern

  1. Have an outer process launch CasperJS with a known state or job identifier.
  2. Let CasperJS stop at a safe checkpoint by writing status to a file, socket, or other agreed channel and exiting, or by waiting on an externally observable condition.
  3. Have the controller read terminal input, validate it, and signal the next stage.
  4. Start or resume the next CasperJS stage with the approved value.

This design avoids assuming that a particular PhantomJS build, operating system, or launch mode delivers interactive stdin to a running CasperJS callback. PhantomJS’s IPC, child-process, REPL, and command-line references are the relevant compatibility documentation: IPC, child process, REPL, and command-line options. Verify the exact mechanism against your installed versions and deployment environment.

Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • 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

Why a busy loop is unsafe

Do not implement “wait for Enter” as a tight JavaScript loop. It blocks the event loop that CasperJS and PhantomJS need for timers, network callbacks, and page events. A controller, a file/socket signal, or a page-side condition is safer than freezing the browser process.

Timeouts, recovery, and debugging

Always define the failure path

A waitFor() timeout should produce an actionable message and a deliberate outcome: stop, retry, capture diagnostics, or continue with a fallback. The API also documents a waitFor.timeout event emitted when a wait operation exceeds its limit. Its details can identify what was awaited, such as a selector.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
casper.on('waitFor.timeout', function (details) {
    this.echo('Wait timed out: ' + JSON.stringify(details), 'ERROR');
});

Use one timeout strategy consistently. A short timeout creates flaky runs on slow pages; an unlimited wait can leave a job stuck indefinitely.

Remember that exit() is asynchronous

CasperJS documents that exit() works asynchronously. Code may continue executing after the call, so do not assume it instantly interrupts the current callback. Return from your callback or guard later actions when an exit has been requested.

Common symptoms and fixes

Symptom Likely cause Fix
The script continues before a person responds A timer was used as human input Move approval to an external controller; do not use wait() for terminal interaction.
waitFor() always times out Wrong selector, frame, page state, or timeout Log the current URL and inspect the DOM; test a condition that can actually become true and increase the explicit timeout only when justified.
Actions run in the wrong order Assuming waitFor is chainable or placing actions outside the queue Put waits and dependent actions in ordered then() steps.
A page prompt appears unanswered The filter message does not match, or the filter was installed too late Register page.prompt before navigation and match the exact message; return a string.
It works locally but not in automation Different PhantomJS/CasperJS version or launch environment Record versions and command-line arguments, then verify stdin/IPC behavior in that same environment.

Inspect your legacy runtime before changing code

  • Record the installed CasperJS version and whether the runtime is PhantomJS or SlimerJS.
  • Check whether the script is launched with a script argument (normal automation) or without one (PhantomJS REPL mode).
  • Confirm that the page’s prompt, selector, or status value is actually present in the frame you are testing.
  • Use explicit timeouts and log the URL, selector, and timeout details on failure.

Because CasperJS is unmaintained, undocumented behavior copied from a different PhantomJS release should not be treated as portable. A small proof in the target deployment is more reliable than assuming REPL examples apply to a scripted run.

Or skip the browser setup

If your real goal is to obtain a clean screenshot after a page reaches its normal state, a screenshot API can remove the CasperJS/PhantomJS setup entirely. ScreenshotNeo is a website screenshot API and MCP server; it accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and whether the request was billed.

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

One GET request returns PNG, JPEG, WebP, or a PDF. The API supports full-page captures with lazy images loaded, CSS-selector element captures, dark mode, device presets or custom viewports, retina scale, PDF paper/margins/orientation/page ranges, custom CSS and JavaScript, pre-capture clicks, selector or network-idle waits, request/resource blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Existing parameter names used by other screenshot APIs also work, easing migration.

cURL

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

Python

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)

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}`);

See the complete parameter reference in the ScreenshotNeo documentation. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients, so an AI agent can request a capture without driving a local browser.

Plan Included shots Price
Free 1,000 per month $0, no card
Starter 3,000 $5
Growth 15,000 $15
Pro 60,000 $39
Scale 250,000 $99
Business 1,000,000 $249

Yearly billing gives two months free, and every feature is included on every plan. Start with 1,000 free screenshots a month with no card; paid plans start at $5 for 3,000.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

FAQ

What is the default waitFor() timeout?

The documented default is 5,000 milliseconds. Pass an explicit timeout when your page needs a different limit.

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

Can page.prompt collect arbitrary keyboard input?

No. It supplies a scripted string to a page JavaScript prompt. It is not a terminal reader or a general keyboard-capture mechanism.

Should I use CasperJS’s REPL for an approval workflow?

Not without verifying the exact PhantomJS launch mode and version. REPL documentation covers a process started without a script argument; it does not document pausing an already running CasperJS script.

What should happen after a timeout?

Choose explicitly: stop with diagnostics, retry with a bounded limit, or execute a documented fallback. Leaving the default behavior implicit makes failures difficult to operate.

Frequently Asked Questions

What is the default waitFor() timeout?

The documented default is 5,000 milliseconds; pass an explicit timeout when needed.

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.

Can page.prompt collect arbitrary keyboard input?

No. It returns a scripted string for a page JavaScript prompt, not terminal input.

Should I use CasperJS’s REPL for approval workflows?

Only after verifying the exact PhantomJS version and launch mode; REPL behavior is not documented as a pause API for scripted CasperJS runs.

The Bottom Line

Use wait() for elapsed time, waitFor() for page state, and page.prompt for scripted page dialogs. For a human typing in the terminal, use an external controller rather than assuming CasperJS can suspend and resume on stdin.

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.