Use two independent time limits. Set page.settings.resourceTimeout before page.open() to bound individual requests, then wrap the whole navigation in a watchdog timer. If the watchdog expires, log the deadline, call page.stop(), and call phantom.exit(1) without waiting for a load callback. In the normal callback, clear the watchdog and exit with a status-based code.
This distinction matters because resourceTimeout is a per-resource setting, not a documented page-wide deadline. Also, PhantomJS does not document that page.stop() will invoke the load callback, so stopping and process termination must be separate steps.
The reliable pattern
The following script gives every navigation a hard deadline while retaining diagnostics for individual stalled resources. The 30-second and 10-second values are examples; choose values for your page, network and runtime.
var page = require('webpage').create();
var finished = false;
var watchdogMs = 30000; // Example overall deadline.
// Must be set before page.open(). This applies per resource.
page.settings.resourceTimeout = 10000;
page.onResourceTimeout = function (request) {
console.log('Resource timeout: ' + request.url +
' (' + request.errorCode + ': ' + request.errorString + ')');
};
var watchdog = setTimeout(function () {
if (finished) return;
finished = true;
console.log('Overall page load deadline exceeded');
page.stop();
phantom.exit(1);
}, watchdogMs);
page.open('https://example.com', function (status) {
if (finished) return;
finished = true;
clearTimeout(watchdog);
console.log('Page load status: ' + status);
phantom.exit(status === 'success' ? 0 : 1);
});
finished prevents a late callback from performing a second shutdown. The watchdog sets it before stopping, so the process exits even if no completion callback arrives. The callback handles the normal path and returns exit code 0 only for success.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
- Model: Dell OptiPlex 7050 Small Form Factor (SFF)
- Processor: Intel Core i7-7700 3.60 GHz
- Memory: 32GB DDR4 Ram
- Storage: 1TB Solid State Drive (SSD) Fast Boot + Storage
- Operating System: Windows 11 Pro (64-bit)
What page.open actually waits for
Completion is callback/event driven
page.open(url, callback) starts navigation. When loading finishes, PhantomJS routes the optional callback through page.onLoadFinished and supplies either success or fail. The handler documentation describes success as a load with no network errors and fail as a load with network errors.
That callback is therefore the normal completion signal, not a promise that resolves after every JavaScript timer or application-level activity has ended. A page can keep the runtime busy with scripts, additional navigation, or other work, and a callback can also be delayed by a condition outside the request you were expecting.
Why a resource timeout is not enough
page.settings.resourceTimeout is measured in milliseconds and applies to an individual resource request. When a request reaches that limit, PhantomJS stops trying that resource, invokes onResourceTimeout, and can continue loading other parts of the page. It does not document a maximum duration for the complete page.open operation.
Consequently, a page may still fail to reach its load callback after one resource timeout, or it may remain stuck for a reason that never produces a resource-timeout event. Use the setting to identify and bound bad dependencies, but use a separate watchdog to guarantee an upper bound for the script.
What page.stop() guarantees—and what it does not
The official API lists page.stop() as the method for stopping a load, but its reference does not promise that stopping causes onLoadFinished or the page.open callback to run. Treat it as a best-effort cancellation request. Follow it with phantom.exit() when the requirement is “the process must end by this deadline.”
Install diagnostics before navigation
Attach the callback correctly
The callback must be the second argument to page.open. If you prefer an event hook, assign page.onLoadFinished before opening the URL. Do not put your only cleanup action in code that assumes one of these hooks will definitely arrive.
Rank #2
- AN AMAZING MAC AT A SURPRISING PRICE — With an incredibly portable and durable aluminum design, up to 16 hours of battery life,* and the A18 Pro chip, MacBook Neo is ready to go wherever school takes you.
- FOUR STUNNING COLORS. ONE DURABLE DESIGN — Choose from four beautiful colors — Silver, Blush, Citrus, or Indigo — each with a color-coordinated keyboard. And MacBook Neo is made with a durable recycled aluminum enclosure that helps it reach 60 percent recycled content by weight — the most ever in any Apple product.*
- FLY THROUGH EVERYDAY ASSIGNMENTS — Whether you’re cramming for finals, using Apple Intelligence* to summarize class notes, creating presentations, or even playing the latest Apple Arcade game,* MacBook Neo delivers the performance and AI capabilities you need to get things done.
- UP TO 16 HOURS OF BATTERY LIFE — MacBook Neo delivers all day battery life, so you can power through from early morning classes to late night study sessions without worrying about plugging in.
- A VIBRANT 13-INCH DISPLAY* — The gorgeous Liquid Retina display on MacBook Neo supports 1 billion colors, so photos and videos pop and text is crisp for easy reading.
page.onLoadFinished = function (status) {
console.log('Load finished: ' + status);
};
page.open('https://example.com');
For a one-shot script, the callback form is usually simpler because it keeps success/failure handling next to the navigation. Either form should still have an independent watchdog.
Log every resource timeout
The timeout handler receives request metadata, including the URL, request time, error code and error text. Record those fields in your CI or service logs; the URL often identifies a third-party analytics, advertising, font or API endpoint that is delaying the page.
Recommended Free Tools
page.onResourceTimeout = function (request) {
console.log(JSON.stringify({
url: request.url,
time: request.time,
errorCode: request.errorCode,
errorString: request.errorString
}));
};
Install this handler before page.open, just as you set resourceTimeout before navigation. The setting affects the initial open call when configured in advance.
Choosing useful timeout values
Set the resource limit for dependencies
Use a resource limit short enough to prevent one dead host from consuming the whole run, but long enough for the slowest legitimate asset in your environment. A ten-second value is only an example, not a PhantomJS default or a universal recommendation. If your page depends on a large document or a private API over a high-latency link, increase it; if third-party assets are optional, decrease it and let the page continue.
Set the watchdog for the whole operation
The watchdog must include DNS lookup, connection setup, redirects, document transfer, resource loading and the JavaScript work that occurs before the load-finished event. A 30-second example is suitable only as a starting point. Measure normal runs in the deployment environment, then leave headroom for the slow tail while preserving a firm upper bound.
Keep the watchdog independent from onResourceTimeout. A resource event is useful evidence, not a completion signal and not proof that the script will terminate.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallRank #3
- Performance: Powered by Intel Celeron N4500 dual-core processor with up to 2.8 GHz burst frequency and 4MB L3 cache, this HP Chromebook delivers smooth multitasking for everyday computing. With 4GB LPDDR4x-2933 RAM and Intel UHD Graphics, enjoy seamless web browsing, video streaming, and productivity apps. Chrome OS boots in seconds and updates automatically, keeping your laptop secure and running at peak performance for students, professionals, and home users.
- Immersive 14-Inch HD Display: Experience clear, vibrant visuals on the 14-inch diagonal HD (1366 x 768) anti-glare display with 250 nits brightness and 62.5% sRGB color accuracy. The micro-edge design maximizes your viewing area with an impressive 80% screen-to-body ratio, perfect for streaming movies, video calls, and document editing. The anti-glare coating reduces eye strain during extended use, making it ideal for all-day productivity and entertainment in any lighting condition.
- Advanced Connectivity & Ports: Stay connected with Wi-Fi 6 (2x2) for faster wireless speeds and Bluetooth 5.3 for seamless device pairing. Equipped with versatile ports including 1 USB Type-C 10Gbps (with USB Power Delivery and DisplayPort 1.4), 2 USB Type-A 5Gbps ports, 1 HDMI 1.4b, and 1 headphone/microphone combo jack. Connect external monitors, transfer files quickly, charge your device, and expand your workspace effortlessly for maximum productivity and flexibility.
- All-Day Battery & Premium Design: The battery keeps you powered throughout your day, while the included 45W USB Type-C power adapter ensures fast charging. Featuring a sleek modern grey finish with vertical brushing pattern on the keyboard deck, this lightweight 3.35 lb Chromebook combines style and portability. The full-size modern grey keyboard and HP Imagepad provide comfortable typing and precise navigation for work, school, or entertainment on the go.
- Enhanced Security & Multimedia: Built-in H1 secure microcontroller protects your data and privacy with enterprise-grade security. The HP True Vision 720p HD camera with integrated dual array digital microphones delivers crystal-clear video calls and online meetings. HD Audio with stereo speakers provides rich, immersive sound for music, videos, and calls. With 64GB eMMC storage, you have ample space for essential files while Chrome OS seamlessly integrates with Google Drive for cloud storage.
A step-by-step implementation
- Create the page. Load
webpageand create one page object. - Configure per-resource timing. Assign
page.settings.resourceTimeoutin milliseconds before opening the URL. - Install logging. Set
page.onResourceTimeoutand record URL, timing and error details. - Start the watchdog. Use
setTimeoutaround the navigation and keep a shared completion flag. - Stop and exit on expiry. Set the flag, log a clear message, call
page.stop(), then callphantom.exit(1). Do not wait for a callback. - Handle normal completion. In the
page.opencallback, return immediately if the watchdog already finished, otherwise clear the timer, inspectstatus, and exit with0for success or1for failure.
Why PhantomJS may appear hung
A watchdog firing without a resource-timeout event does not identify a single root cause. It establishes only that the overall deadline passed. Investigate the runtime and the environment rather than assuming the last requested asset is responsible.
- Callback wiring: verify that the callback is actually passed to
page.open, or thatpage.onLoadFinishedis assigned before navigation. - Navigation behavior: inspect pages that redirect, trigger client-side navigation, or run long scripts during startup.
- DNS, TLS and proxy access: run the same URL from the PhantomJS host and check name resolution, certificates, outbound firewall rules and proxy settings.
- Runtime/version differences: reproduce with the exact PhantomJS binary and operating system used in production. Legacy documentation does not establish compatibility for every release.
- Process shutdown: ensure every terminal path reaches
phantom.exit(). The official Quick Start warns that PhantomJS will not terminate unless an exit call is reached.
Failure modes and fixes
The script prints a resource timeout but never exits
Cause: the resource handler is diagnostic; it does not terminate the page or process.
Fix: retain the independent watchdog. If the page later reports fail, clear the watchdog and exit nonzero in the callback; if it never reports, the watchdog performs the shutdown.
The watchdog fires, but the callback later prints another result
Cause: stopping did not prevent a queued callback.
Fix: guard both paths with the same finished flag and set it before calling page.stop().
The timeout setting seems ignored
Cause: it was assigned after page.open, or the perceived hang is not an individual resource request.
Fix: move the assignment before navigation, install onResourceTimeout, and rely on the watchdog for page-wide enforcement.
Rank #4
- [INTEL POWERED CONTENT] - Built with a 8th Generation Hexa-Core Intel i5 and 32GB of DDR4 RAM; Modern, Windows 11 ready, with 4K support, Executive multitasking, media streaming and smooth, multi-tab web browsing; Perfect as an all-purpose multimedia computer; built for content creators; Plenty of RAM and Mass storage for photo and video editing powered by Intel HD 630
- [LATEST WIRELESS TECH] - This Dell Desktop Computer easily connects to the internet through the Built In WiFi / Bluetooth
- [SOLID STATE STORAGE] - This Dell Computer setup comes with an ultra-fast 1TB Solid State Drive (SSD); Setup as the primary boot device; Boot and load programs with lightning speed ; Additional expansion available
- [BUY & OWN WITH CONFIDENCE] - From the world's largest Microsoft Authorized Refurbisher; Quality Guarantee and Free Tech Support; Award-winning Customer Service; | Support Sustainable Business
- [MODERN HI-SPEED PORTS] - USB 3.0 (x4) | USB 2.0 (x4) | DisplayPort (x1) | HDMI Port (x1) | Audio Combo Jack (x1) | Audio Out (x1) | RJ-45 Ethernet (x1) | Internal SATA (x3)
The process stays alive after a successful load
Cause: the callback completed work but never called phantom.exit().
Fix: make the callback’s final action an explicit exit, as in the sample, and ensure asynchronous cleanup cannot bypass it.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →The process exits too aggressively
Cause: illustrative limits were copied without considering the target site’s normal latency.
Fix: collect elapsed times in the real environment, then raise the resource or watchdog limit while keeping a finite deadline. Do not remove the watchdog merely to accommodate a slow page.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If your goal is simply to obtain a dependable website image or PDF rather than maintain a legacy PhantomJS browser, 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. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers report the page verdict and billing result.
Use the API documentation at https://screenshotneo.com/docs/ for parameters and response details. A cURL request is:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The equivalent Python request is:
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)
And 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}`);
ScreenshotNeo also has an MCP server with take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. You can sign up free.
Best Value
- 🖥POWERFUL PROCESSOR and SUPERIOR STORAGE: Configured with top of the Intel Core i5 processor for lightning-fast, reliable and consistent performance to ensure an exceptional PC experience. 16GB RAM memory to smoothly run multiple applications and browser tabs all at once. 2TB HDD storage space to store apps, games, photos, music, and movies. Loaded with 16GB to zip through multiple tasks in a hurry without lag.
- 🖥️New 22 Inch Full HD (1920x1080) LED monitor: with 75hz, High-Quality panel with quick refresh rate and response time. With 1080p resolution, you can enjoy gaming or a modern computing experience. 22 Inch monitor has a Smart Contrast to provide optimized image quality. Bezel-less and sleek design with glossy finish, crisp edge-to-edge visuals. Wide Viewing Angles for clarity from any viewpoint. VESA Mountable and built-in tilt options allow for a variety of monitor configurations.
- ⌨️ +🖱️ RGB KEYBOARD AND MOUSE | RGB SPEAKER: 3 LED Colors - Blue, red, green, Backlight LED Lights for use at night time, looks amazing. The keyboard mouse and speaker are responsive, reliable, and probably plastered in RGB lights. It's important you pick the right one for your desktop.
- 💿 WINDOWS 10 Pro LATEST: A new installation of the latest Microsoft Windows 11 Professional 64 Bit Operating System software, free of bloatware commonly installed from other manufacturers. As Microsoft's latest and best OS to date, Windows 10 Pro 64 Bit will maximize the utility of each PC for years to come. Optional software such as Anti-Virus and Office 365 can also be easily downloaded through the Microsoft Windows App Store.
Operational and cost considerations
Make exit codes meaningful
Use zero only when the page reports success. Return nonzero for fail and watchdog expiry so shell scripts and CI can distinguish a completed capture from a failed one. Include the URL, elapsed time and final status in logs.
Prevent duplicate work
One page object and one watchdog per navigation keeps ownership clear. If a larger script opens several URLs, create a fresh completion state and timer for each operation, and clear each timer on its matching callback. Never let a previous timer terminate a later navigation.
Interpret timeout logs carefully
A timed-out request may be optional, and its removal can allow the document to finish successfully. Conversely, a page-wide watchdog can fire with no resource event. Treat logs as evidence to narrow DNS, TLS, proxy, navigation and runtime investigations, not as proof of a specific cause.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsFAQ
Does resourceTimeout stop page.open?
No. It bounds an individual request and invokes onResourceTimeout; it is not documented as a complete page-load deadline.
Will page.stop() invoke my callback?
There is no documented guarantee. Call phantom.exit() independently when the watchdog expires.
What does a fail status mean?
The load-finished documentation defines fail as a load with network errors. It is distinct from a watchdog expiry, where no completion status may arrive.
Are 10 and 30 seconds PhantomJS defaults?
No. They are illustrative values in the example. Tune both limits for your URL and execution environment.
Frequently Asked Questions
Can I rely only on onResourceTimeout for cleanup?
No. That event reports a request-level problem and does not guarantee that the page or PhantomJS process will exit. Keep a separate watchdog and explicit phantom.exit call.
Should I call phantom.exit immediately in onResourceTimeout?
Only if your application intentionally treats any timed-out dependency as fatal. Otherwise log the request, allow the page to continue, and let the normal callback or overall watchdog decide the final result.
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.

