Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
HTTP 402 is a response from the page or another server, not proof that CasperJS’s capture() method is broken. First find the exact request that returned 402, then inspect its status text, headers and body. Only after you know what the site is asking for can you choose a permitted remedy. A 402 may be used for an application-specific access policy; the status alone does not prove that payment, bot blocking or any other single cause is involved.
What HTTP 402 means in a CasperJS run
HTTP status codes describe responses to requests. CasperJS’s capture() and captureSelector() methods save what the browser rendered; they do not determine the meaning of a server response. RFC 9110 describes 402 as “reserved for future use,” so there is no universal behavior that CasperJS can automatically fix.
The response can belong to the main document, a script, an image, an iframe or another resource. Those cases look similar in a console unless you log the resource URL. A page that returns a normal document but loads one 402 resource is a different problem from navigation itself receiving 402.
Recommended Free Tools
1. Confirm which request returned 402
Log the status-specific event
CasperJS exposes HTTP status events using the http.status.[code] pattern. Register the 402 event before opening the page:
#1 Best Overall
var casper = require('casper').create({
verbose: true,
logLevel: 'debug'
});
casper.on('http.status.402', function (resource) {
this.echo('402 URL: ' + resource.url, 'ERROR');
this.echo('Status: ' + resource.status, 'ERROR');
this.echo('Status text: ' + (resource.statusText || ''), 'ERROR');
});
casper.start('https://example.com/', function () {
this.echo('Navigation completed: ' + this.getTitle());
});
casper.run(function () {
this.echo('Finished');
this.exit();
});
Replace the URL with the target you are authorized to access. The event confirms that a response with status 402 was observed and identifies its URL; it does not bypass the site’s policy.
Use the HTTP status handler option
For a reusable script, configure httpStatusHandlers. The handler receives the resource information supplied by CasperJS:
var casper = require('casper').create({
httpStatusHandlers: {
402: function (resource) {
this.echo('402 from ' + resource.url, 'ERROR');
}
}
});
casper.start('https://example.com/');
casper.run(function () {
this.exit();
});
You can keep both approaches while diagnosing a difficult run, but avoid performing the same recovery action twice. A status handler is useful for recording the event; it cannot turn a denied response into an authorized one.
Inspect every resource, not just the document
Resource callbacks let you correlate a response with its URL and response metadata. Add logging around requests and responses, while avoiding sensitive cookie or authorization values in shared logs:
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
var casper = require('casper').create({
verbose: true,
logLevel: 'debug'
});
casper.on('resource.received', function (resource) {
if (resource.status === 402) {
this.echo(JSON.stringify({
url: resource.url,
status: resource.status,
statusText: resource.statusText || '',
headers: resource.headers || []
}, null, 2), 'ERROR');
}
});
casper.start('https://example.com/');
casper.run(function () {
this.exit();
});
Depending on the CasperJS and PhantomJS combination, response-body fields may be available on the resource object. If they are present, record the body for diagnosis, preferably after redacting tokens, personal data and payment details. If they are not exposed in your runtime, reproduce the request with an authorized HTTP client or inspect the site’s server logs.
2. Separate navigation from screenshot capture
Do not call the screenshot operation until you know whether the expected document loaded. A minimal diagnostic-and-capture script is:
var casper = require('casper').create({
verbose: true,
logLevel: 'debug'
});
casper.on('http.status.402', function (resource) {
this.echo('402: ' + resource.url, 'ERROR');
});
casper.start('https://example.com/', function () {
this.echo('Current URL: ' + this.getCurrentUrl());
this.echo('Title: ' + this.getTitle());
if (this.exists('body')) {
this.capture('/tmp/example.png');
} else {
this.echo('No body element; not capturing', 'ERROR');
}
});
casper.run(function () {
this.exit();
});
If the main document is the 402 response, the title and body may be an error page. If the document is valid but an image or API call is 402, the screenshot may still be created while part of the page is missing. Treat those outcomes differently in your pipeline.
Free tools Windows power users keep installed
One-click scans. No signup required.
3. Read the response before choosing a fix
Check the response body
The body often states the actual requirement: an account flow, a subscription gate, an API quota, a signed request, a regional restriction or an application-specific protocol. Quote the relevant message in an internal ticket, but do not publish credentials or personal information.
Rank #3
Check headers and redirects
Record the final URL, redirect chain where available, status text and response headers. Headers can identify a required challenge, a documentation URL, a content type or a protocol-specific field. A 402 generated by an intermediate proxy is not necessarily the policy of the origin site.
Check request context
- HTTP method: a GET and POST can have different access rules.
- Cookies and session state: a logged-out browser may receive a different response from an authenticated session.
- Authorization and custom headers: confirm that values are present only when the site documents them.
- User agent, IP region and referrer: these can affect routing, but changing them to evade controls may violate terms.
- Timing: a token or checkout session may have expired between page load and resource fetch.
The x402 protocol is one example of a payment-oriented use of 402 headers, but seeing 402 does not establish that this protocol, or payment of any kind, is involved. Follow the target service’s documentation or contact its operator.
4. Apply a permitted remedy
When access requires an account or subscription
Complete the provider’s documented sign-in or subscription flow, then supply the resulting session in the supported way. CasperJS should not be used to defeat a paywall, CAPTCHA, bot check or access control. If automated access is not allowed, request an API, export or screenshot permission instead.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11When an API requires a token or payment header
Use the exact header, endpoint and request method documented by that API. Keep secrets outside the script—for example, inject them through the environment—and never print them in resource logs. A browser screenshot of an API error is not a substitute for making the API request correctly.
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
When only a secondary resource returns 402
Identify whether the resource is optional. You may be able to hide a broken widget, use the site’s documented fallback, or capture after the page reaches a usable state. Do not silently present an incomplete image as a successful full-page capture; record the missing resource and decide whether the result is acceptable.
When the response appears to be a proxy or gateway error
Compare the URL, headers and body from the browser with a request made from the same network. Ask the proxy or hosting operator for the policy that generated the response. Retrying indefinitely rarely helps and can increase load or trigger rate limits.
5. Make the script reliable after the cause is known
Wait for a meaningful page state
Use a selector or a deliberate delay only when the site requires it. A fixed delay can hide slow-load failures; waiting for a selector gives your script a testable condition:
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorscasper.start('https://example.com/');
casper.waitForSelector('#main-content', function () {
this.capture('/tmp/ready.png');
}, function () {
this.echo('Timed out waiting for #main-content', 'ERROR');
});
casper.run(function () {
this.exit();
});
Choose a timeout appropriate to the page and log whether the selector appeared. A timeout, blank page or failed file write is a separate failure class from HTTP 402.
Best Value
Verify the output file
- Use an absolute path that the CasperJS process can write.
- Check that the file exists and has a non-zero size after
run(). - Ensure the output directory exists and has sufficient space.
- For
captureSelector(), verify that the selector matches the intended element before capturing.
Check runtime compatibility
CasperJS is no longer actively maintained. Its project information notes that versions through 1.1-beta3 do not support PhantomJS 2.0 and newer. That compatibility issue can explain startup or rendering errors, but it does not, by itself, explain a server returning HTTP 402. Record the CasperJS and PhantomJS versions when reporting a problem and test a supported combination in an isolated environment.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Common symptoms and fixes
| Symptom | Likely location | Next action |
|---|---|---|
| 402 event names the main page URL | Navigation response | Read the body and headers; follow the site’s documented access process. |
| 402 event names an image, script or iframe | Secondary resource | Decide whether the resource is required and investigate that URL separately. |
| Screenshot file is missing | Filesystem or script flow | Check selector logic, output path, permissions and whether capture was reached. |
| Screenshot exists but is blank | Rendering or premature capture | Wait for a real page-state selector and inspect the loaded URL and DOM. |
| Repeated 402 responses after retries | Site policy or expired context | Stop retrying; obtain the required authorization or contact the operator. |
| Script fails before navigation | Runtime compatibility | Check CasperJS/PhantomJS versions and JavaScript errors separately. |
Or skip the browser setup
If you need a permitted screenshot rather than CasperJS-specific browser control, ScreenshotNeo provides a single HTTP request and an MCP server for AI clients. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups and chat widgets; each step can be disabled. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers.
See the ScreenshotNeo documentation for all options, including full-page capture, CSS selectors, device presets, custom headers and cookies, waits, blocking rules, PDF output, signed links, asynchronous jobs and bulk capture.
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 →Clear out junk files and repair common Windows errorsFree Scan →curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
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 also offers take_screenshot, get_page_info and capture_pdf through MCP for Claude, Cursor and other MCP clients. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account to get an API key.
FAQ
Does 402 always mean the page requires payment?
No. The standard reserves the code for future use, and individual services define their own behavior. The response body, headers and request URL are required to identify the policy.
Can CasperJS ignore a 402 and capture anyway?
It can save whatever document or partial page was rendered, but ignoring the status does not grant access to missing content. Log the response and label incomplete captures.
Should I keep retrying?
Only retry when the service documents a transient condition and gives a safe retry policy. Repeated identical 402 responses normally require a change in authorization or request context, not more retries.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →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.

