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.

If PhantomCSS saves several screenshots from a loop but they all show the first page, the loop is probably running faster than the page changes finish. Queue each page change and capture as a separate CasperJS step, wait for a page-specific ready condition, and give every image a unique name. A fixed delay alone is less reliable because page-load time varies.

Why a loop can capture the same page repeatedly

PhantomCSS is a CasperJS module for capturing screenshots and comparing them with baseline images using Resemble.js. A JavaScript for loop runs synchronously: it can issue several page-change operations and screenshot calls before asynchronous navigation, requests, or DOM updates have completed. The captures may therefore happen while the browser still displays the first state.

This symptom has been reported with a loop that changes pages and captures them inside one CasperJS then callback. Moving each iteration into the CasperJS step queue and waiting for the expected page state addresses the timing problem. CasperJS documents ordered steps and wait operations for this purpose: CasperJS API documentation. The reported eight-second delay in that issue is not a general setting; it may be too short for one page and unnecessarily long for another.

Queue one capture step per page

Adapt the page-change function and readiness condition to your application. In this example, moveNext is application-specific, and #page-number is a placeholder selector that should identify the page currently shown.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
var firstPage = 1;
var lastPage = 10;

for (var pageNo = firstPage; pageNo <= lastPage; pageNo++) {
    (function (targetPage) {
        casper.then(function () {
            this.evaluate(function (page) {
                moveNext(page); // application-specific page change
            }, targetPage);

            this.waitFor(function () {
                return this.evaluate(function (page) {
                    var indicator = document.querySelector('#page-number');
                    return indicator &&
                        indicator.textContent.trim() === String(page);
                }, targetPage);
            }, function () {
                phantomcss.screenshot('html', 'page-' + targetPage);
            }, function () {
                this.die('Timed out waiting for page ' + targetPage);
            }, 10000);
        });
    }(pageNo));
}

casper.run();
  1. Capture the loop value. The immediately invoked function expression passes the current number as targetPage. This avoids older JavaScript environments in which queued callbacks might otherwise all observe the loop’s final value.
  2. Make the page change. Replace moveNext(page) with the action your application uses to navigate or update its view. If a click or request triggers the transition, ensure it is actually initiated in this step.
  3. Wait for evidence of the new state. The condition checks that the page indicator equals the target number. Use a marker that changes only after the desired content is ready.
  4. Capture only after readiness. The screenshot is inside the successful wait callback, so a slow or unfinished transition is not silently captured as the previous page.
  5. Fail visibly on timeout. The timeout callback stops the run with the page number it was waiting for. Adjust the timeout to your application’s expected response time rather than treating the example value as universal.

CasperJS also documents waits for selectors, text, and resources. Choose the signal that most reliably means the specific page is ready. Its wait-family methods are not chainable; when you need them in an ordered flow, wrapping them in casper.then is the documented pattern: CasperJS API documentation.

Choose a readiness signal that matches the page

A useful condition distinguishes the intended page from the previous one; merely checking that the document exists is not enough if that document remains present during the transition.

  • Page number or route state: check a visible page indicator, active tab, or route value that changes for each iteration.
  • Unique text: wait for text that is specific to the target page, not generic copy shared by all pages.
  • Target element: wait for a selector that appears only when the page’s key content is ready.
  • Resource completion: if a specific request determines the rendered state, wait for that resource or for a DOM change it causes.

CasperJS’s FAQ notes that intermittent test failures often occur when a test runs before a needed resource or element is available, and recommends waiting for DOM nodes, text, or resources: CasperJS FAQ. If a page can update its marker before its main content arrives, wait for a second condition that confirms the content itself.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Use unique names and verify the output

Pass a distinct, meaningful name to each PhantomCSS screenshot call, such as page-1, page-2, and so on. PhantomCSS otherwise documents generated names such as screenshot_0.png; explicit names make it easier to identify which iteration produced each file and to match captures with baselines. See the PhantomCSS documentation.

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

After a run, check that the expected filenames exist and that each readiness marker matched the intended value. If images still look identical, inspect the page-change handler and the marker itself: the function may not be changing the view, or the marker may be shared across pages and therefore report readiness too early.

Fixed delay or condition-based wait?

Approach When it can help Limitation
Fixed delay Useful as a temporary diagnostic when a page has no reliable readiness signal. A delay that works on one run may be too short under slower conditions or waste time when the page is fast. The eight-second delay in the reported issue is specific to that example, not a general recommendation.
Condition-based wait Preferred when the application exposes a page-specific DOM, text, or resource signal. The condition must genuinely correspond to the intended rendered state; a stale or generic marker can succeed too early.

Use a condition-based wait as the default. If you temporarily add a delay to diagnose timing, retain a timeout and replace the delay with a readiness check once you identify a dependable signal.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Keep visual regression captures stable

Even correctly sequenced screenshots can differ between runs if the page contains mutable content. PhantomCSS recommends predictable UI and suggests static pages or faked data when changing content would make comparisons unstable: PhantomCSS documentation.

  • Use controlled test data where practical.
  • Make sure animations, rotating content, or asynchronous updates do not change the target state during capture.
  • Keep the expected state and screenshot name paired, so a failure can be traced to a specific iteration.

Troubleshoot common failures

Every file shows the first page

The page transitions likely have not completed before capture, or the page-change function is not changing the view. Put each transition and capture in its own queued CasperJS step, then wait for a marker that updates to the target page.

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

Every filename represents the last page

A callback may be reading the loop variable after the loop has finished. Capture the current value in a closure, as the example does with targetPage, and build the name from that captured value.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

The wait times out

Check that the selector exists on the page, that its text format matches the comparison, and that the page-change action receives the expected target number. If the app updates asynchronously, wait for the completion signal rather than only for the action to be issued. A timeout should reveal a real missing transition, not be removed to force a screenshot.

Some runs pass and others fail

The readiness signal may occur before the dependent content or resource is ready. Choose a later, more specific marker, or wait for the needed element, text, or resource as CasperJS’s FAQ recommends. Also make the test data and UI predictable to reduce unrelated visual changes.

The screenshots have unique names but identical contents

Distinct filenames only distinguish outputs; they do not make the page state distinct. Log or inspect the target page value and verify the page-change handler and readiness marker for each step before changing PhantomCSS configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check runtime compatibility before adopting this stack

The documented APIs and reported symptom establish a historical CasperJS and PhantomCSS workflow, but they do not establish whether PhantomCSS, CasperJS, or PhantomJS is currently maintained or suitable for a new project. Check current releases and runtime compatibility for your environment before building a new test system around them.

Or skip the browser setup

If the goal is to request a website screenshot without maintaining a CasperJS loop, ScreenshotNeo provides a screenshot API and MCP server for developers. A GET request returns a PNG, JPEG, WebP, or PDF; the API’s options include full-page captures, element selection, waits, and custom CSS or JavaScript. See the ScreenshotNeo API documentation.

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

For example, change the URL to the page you want. Cookie banners, popups, and chat widgets are removed before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up free for ScreenshotNeo.

Frequently Asked Questions

Does PhantomCSS itself provide the wait for a page change?

In this pattern, CasperJS performs the ordered steps and waits; PhantomCSS is called to capture after the readiness condition succeeds.

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

Is an eight-second delay the recommended fix?

No. It was used in one reported case. A page-specific readiness condition is a better default.

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.