Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
CasperJS can pause its step queue for a fixed delay or until a page condition becomes true, and it can answer a website’s JavaScript prompt() automatically. Those are three different operations. The official API documentation reviewed here does not document a supported way for an already-running CasperJS script to stop and wait for a person to type into the terminal. Choose the mechanism that matches what you mean by “user input,” rather than treating a timer as a human pause.
Choose the kind of input you mean
CasperJS scripts run through an asynchronous step queue. The right way to resume therefore depends on what event should release the next step:
| What should release the script? | Mechanism | What it does not do |
|---|---|---|
| A known amount of time passing | casper.wait(milliseconds, callback) |
It does not wait for a person; it resumes when the timer expires. |
| A page becoming ready | casper.waitFor(test, then, onTimeout, timeout) |
It does not accept terminal input. |
A website’s JavaScript prompt() |
The page.prompt filter |
It supplies a scripted response; it does not display a terminal prompt for an operator. |
| A person typing while the script is running | An external process/controller interaction designed for the runtime | The reviewed CasperJS API does not document a direct terminal-input pause-and-resume method. |
The CasperJS API describes wait() as pausing the steps suite for a specified time, and waitFor() as waiting until a function returns true before processing the next step. See the CasperJS API reference.
Pause for a fixed delay
Use wait() when a known delay is useful—for example, a brief pause after an action where the next step should run after the timer. Pass milliseconds, and optionally provide a callback that becomes a CasperJS step when the wait ends.
#1 Best Overall
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();
Here, the first callback runs after 1,000 milliseconds, and the following then() step runs afterward. This is not an operator checkpoint: if a person needs longer than the delay, the script continues without them. Choose a condition-based wait instead when the page state, rather than elapsed time, is the real trigger.
Resume when a page condition is true
Use waitFor(test, then, onTimeout, timeout) when the next action depends on an observable page state, such as a selector appearing. The test function must return true for CasperJS to continue. The documented default timeout is 5,000 milliseconds; set an explicit timeout when the expected wait may take longer, and define what to do if it expires.
var casper = require('casper').create();
casper.start('https://example.com/');
casper.then(function () {
this.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.run();
The example places waitFor() inside a then() step because the API says waitFor methods are not chainable. Its timeout callback reports the problem and requests exit. CasperJS documents that exit() works asynchronously, so do not assume it instantly interrupts the current callback; avoid putting essential work after that call on the assumption it cannot run.
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
Pick a useful condition
A condition should represent the state needed by the next step, not merely the passage of time. For example, waiting for a selector is more meaningful than sleeping for an arbitrary interval if the next action needs that element. The test function should be safe to evaluate repeatedly while the wait is pending.
Set timeout and recovery deliberately
A timeout is a limit, not a guarantee that the page is ready when it expires. Decide whether a failure should stop the run, save diagnostic information, or trigger another recovery action. The CasperJS FAQ recommends wait* methods when resources or dynamic DOM content may not yet be available, to reduce intermittent test failures: CasperJS FAQ.
Answer a page JavaScript prompt automatically
If the page itself invokes JavaScript prompt(), install a page.prompt filter and return the string the page should receive. This handles a browser dialog programmatically; it does not pause the script for a human to enter an answer.
Rank #3
- 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
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/');
casper.run();
The documented filter signature is message, value, and its return type is a string. Match the prompt message you expect and return an appropriate value. Returning currentValue for other messages preserves their current value rather than applying the example answer indiscriminately. See CasperJS Events & Filters.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Can CasperJS wait for terminal input?
Do not infer terminal-input support from CasperJS waits or from PhantomJS’s separate REPL. The CasperJS waits are suite steps. PhantomJS documentation separately covers standard input/output/error as inter-process communication, child-process streams, a REPL started without a script argument, and command-line behavior. The reviewed documents do not specify a direct supported API that suspends an active CasperJS navigation step until a person enters a line.
If a human must approve or provide data during a run, put that interaction at the process/controller boundary for the exact PhantomJS version and launch environment, or move the prompt into an external controller and have the automation continue from a signal or condition. Verify the mechanism in that environment. In particular, do not assume that the REPL’s behavior applies to a script launched through CasperJS.
Rank #4
- PhantomJS inter-process communication
- PhantomJS child process API
- PhantomJS REPL
- PhantomJS command-line documentation
Debug a wait that does not resume
The selector never appears
Check that the selector is correct and that the page actually reaches the state the test checks. A selector wait only resumes when the test returns true. Increase the timeout only if the page legitimately needs more time; a longer timeout cannot fix an incorrect selector or a state the page never reaches.
The wait expires without a useful explanation
Supply an onTimeout callback with a clear message and an explicit policy: stop, collect diagnostics, or try another recovery step. CasperJS also documents a waitFor.timeout event for a wait* operation that exceeds its timeout; its details object can identify what was being awaited, such as a selector. See the API and filter references linked above.
Recommended Free Tools
The script continues after calling exit
Because CasperJS documents exit() as asynchronous, treat it as a request to end the run, not a synchronous throw that prevents every later statement in the current callback from running. Structure the timeout callback so it does not depend on immediate termination.
Best Value
A prompt is not answered as expected
Confirm that the page is invoking JavaScript prompt(), rather than a custom HTML form or an operating-system dialog. Compare the message in the filter with the page’s actual prompt text and return a string. A filter does not make CasperJS wait for a terminal operator.
Check the legacy runtime before relying on examples
CasperJS’s repository states that the project is no longer actively maintained, and the API reference cited here is labeled CasperJS 1.1.0-DEV. These are legacy references, not proof that a particular script has been tested against your installation. Check the CasperJS and PhantomJS or SlimerJS versions you actually run, along with how the script is launched, before adopting runtime-specific behavior. The repository is at github.com/casperjs/casperjs.
Or skip the browser setup
If your goal is to capture a page rather than control a CasperJS session, ScreenshotNeo is a website screenshot API and MCP server for developers. It does not add terminal input to CasperJS; it offers a separate way to request a screenshot or PDF.
One GET request returns a screenshot or PDF. For example, this cURL call saves a WebP screenshot of Stripe; replace the URL with the page you need and provide your API key:
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 the API parameters. ScreenshotNeo removes cookie/consent banners, newsletter popups and chat widgets before capture; those cleanup steps can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info and capture_pdf for AI agents and MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000, and every feature is available on every plan. Sign up for 1,000 free screenshots a month with no card.
Which method should you use?
- Use
wait()only when the intended trigger is elapsed time. - Use
waitFor()when the page must reach a detectable state; configure an explicit timeout and failure path. - Use
page.promptto supply a scripted answer to a page’s JavaScript prompt. - For live operator input, design and verify an external controller/process interaction for your actual runtime instead of assuming the CasperJS step queue reads terminal input.
Frequently Asked Questions
Does CasperJS have a built-in pause-until-I-press-Enter command?
The reviewed official CasperJS API does not document a supported terminal-input pause-and-resume method for an active script.
Should I use wait() or waitFor() for a page that loads unpredictably?
Use waitFor() when you can express readiness as a condition; use wait() only when a fixed delay itself is the requirement.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
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.

