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

If nightmare.screenshot() resolves to a zero-length or apparently blank buffer, separate two problems first: whether your promise chain received the result, and whether Electron produced any pixels. Nightmare.js documents a pathless .screenshot() as returning PNG image data in a Node.js Buffer; an empty image can therefore indicate capture state, especially a hidden or occluded Electron window, rather than an incorrect return type.

Check the returned value, record your Nightmare.js and Electron versions, then compare a visibly rendered capture with one taken while hidden, minimized or covered. The Electron reports most relevant to this symptom involve specific Windows releases and window states, so there is no single fix that applies to every installation.

What a successful Nightmare.js screenshot returns

Nightmare.js describes .screenshot([path][, clip]) as a PNG capture of the current page. When you omit path, the method returns a Buffer containing the image data. Supplying a path changes the practical diagnostic: Nightmare writes the file instead of handing image bytes to your final callback.

Start with a minimal result check so you know whether the problem is promise handling or image content:

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.
const Nightmare = require('nightmare');

const nightmare = Nightmare({ show: true });

nightmare
  .goto('https://example.com')
  .wait('body')
  .screenshot()
  .then(buffer => {
    console.log('is Buffer:', Buffer.isBuffer(buffer));
    console.log('length:', buffer && buffer.length);
    if (!buffer || buffer.length === 0) {
      throw new Error('Nightmare returned an empty screenshot buffer');
    }
    require('fs').writeFileSync('example.png', buffer);
  })
  .catch(console.error)
  .then(() => nightmare.end());

The value logged inside the final .then() is the completed screenshot result. Do not inspect a variable before the chain has resolved, and do not assume that a path-based call will also provide a buffer.

Diagnose the capture state before changing code

Record the runtime matrix

Write down the Nightmare.js version, the Electron version bundled or installed by your project, the operating system, and the BrowserWindow state at capture time. Include whether the window is visible, hidden, minimized or covered by another window. Electron’s capture behavior and the reported failures are version- and platform-specific.

Compare visible and non-visible captures

Run the same page twice: once with the browser visibly rendered and once with your normal headless or hidden configuration. If the visible image works but the hidden image is empty, you have isolated a window-state problem rather than a selector, file-writing or PNG-decoding problem.

Electron’s BrowserWindow.capturePage() resolves to a NativeImage. Its documentation warns that a non-visible page can produce an empty capture rectangle. Electron considers a hidden window capturable when its capturer count is non-zero; current documentation also describes a stayHidden option for keeping a page hidden while allowing capture. Check the documentation that matches your installed Electron version before adopting that option, because Nightmare.js may bundle an older Electron API.

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

Check that the page has actually rendered

Wait for a concrete DOM condition rather than relying on an arbitrary delay. A useful first test is .wait('body') or a selector that appears only after your application has mounted. This does not guarantee that fonts, images or client-side data are complete, but it distinguishes “capture ran before the document existed” from a window-visibility failure.

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.
nightmare
  .goto('https://your-site.example/dashboard')
  .wait('#dashboard-ready')
  .screenshot()
  .then(buffer => {
    console.log({ bytes: buffer.length });
  });

The available evidence does not establish one universal delay or promise sequence for every Nightmare.js release. Treat readiness as an application-specific condition and inspect the exact value returned by the screenshot step.

Common causes and targeted fixes

The result is not being read from the promise

Symptom: Your code prints undefined, a stale variable or no value, although a file may be written when a path is supplied.

Fix: Return or await .screenshot() and inspect its value in the next promise step. Keep error handling on the same chain. A pathless call should be tested with Buffer.isBuffer(result); a path call should be verified by checking the file after the chain completes.

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

The Electron window is hidden

Symptom: A visible run succeeds, but a run using show: false or an explicit hide() creates an empty image.

Fix: Temporarily capture with the window visible. If that succeeds, investigate the Electron version’s capture-visibility rules and Nightmare’s window lifecycle. Do not blindly copy a workaround from a different Electron release. The issue report involving Windows 10 and Electron 21.1.0 describes an empty NativeImage after hiding a window; its proposed show/hide handling was platform-specific and was not presented as a universal Nightmare.js fix.

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.

The window is fully occluded

Symptom: The window exists but is covered by another window, a remote-desktop surface or a compositor state that suspends rendering.

Fix: Repeat the capture with the window unobstructed. An Electron issue reported a 0-by-0 image for a fully occluded BrowserWindow on Windows 11 with Electron 16.0.1. That report links the behavior to Chromium surface-copy limitations when a renderer is suspended. It is evidence for that particular environment, not proof that every empty buffer has the same cause.

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

The page is below the fold or the clip is invalid

Symptom: A capture of a particular element or clip is empty while a full-page capture works.

Fix: First capture the full page without a clip. Then verify that the target selector exists, has non-zero layout dimensions and is within the document you actually loaded. The commonly cited “screenshot buffer length 0” question concerns an element below the fold, but it does not establish a general fix for all empty Nightmare.js buffers. Treat it as a case-specific clue, not a diagnosis.

The navigation failed or produced a blank document

Symptom: The buffer is technically present but decodes to a blank image, or its dimensions are zero.

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

Fix: Log the URL after navigation, inspect page errors, and wait for a selector that proves the application loaded. Test the same URL in a visible run. Authentication redirects, certificate errors, bot checks and JavaScript exceptions can leave a document that is technically capturable but visually empty.

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

A repeatable debugging procedure

  1. Confirm the API mode. Remove the path argument and log Buffer.isBuffer(result) and result.length. If you need a file, write the returned buffer yourself during diagnosis.
  2. Capture a known-simple page. Use a small public page such as https://example.com. This removes application JavaScript and authentication from the first test.
  3. Make the window visible. Run with Nightmare’s visible setting and avoid minimizing or covering the BrowserWindow.
  4. Add a real readiness condition. Wait for a stable selector in your page. Do not claim that a fixed timeout works for all sites.
  5. Inspect dimensions. Decode the PNG with your normal image tooling or inspect the underlying Electron NativeImage if you are instrumenting Nightmare. A 0-by-0 result points toward capture state; a normal-size blank page points toward rendering or navigation.
  6. Build a small reproduction. Keep only goto, one readiness wait and screenshot. Record OS, Nightmare.js, Electron and window state for every run.
  7. Compare versions deliberately. If the reproduction changes behavior after an Electron upgrade or downgrade, consult that release’s BrowserWindow documentation and issue history. Do not assume a workaround reported for Electron 16 or 21 applies to your version.

What to log in CI

  • Nightmare.js and Electron versions.
  • Operating system and architecture.
  • Whether the BrowserWindow was visible, hidden, minimized or occluded.
  • Navigation URL and the selector used as the readiness condition.
  • Buffer length, decoded image dimensions and any navigation or renderer errors.
  • Whether the same commit succeeds when run with a visible window.

These fields let you distinguish a promise-chain regression from a compositor or visibility regression without guessing.

Performance and reliability considerations

Keeping a window visible is a diagnostic measure, not necessarily a permanent CI policy. A visible Electron window can conflict with parallel jobs or desktop sessions, while a hidden window may expose platform-specific capture failures. If hidden captures are required, pin and document the Electron version that works in your environment, run a small smoke capture on each machine image, and retain the image dimensions in logs.

Prefer a selector-based readiness condition over a long global delay: it usually reduces unnecessary waiting while making failures explainable. For flaky pages, capture a simple diagnostic page and your application separately so a network or rendering failure is not mistaken for an empty-buffer API failure.

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

Or skip the browser setup

If your goal is a reliable URL screenshot rather than debugging Nightmare’s embedded Electron window, ScreenshotNeo provides 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; each step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and each response reports the page verdict and billing status in X-Page-Verdict and X-Billed headers.

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.

One GET request returns PNG, JPEG, WebP or PDF output. The API supports full-page captures with lazy images loaded, CSS-selector element shots, device presets and custom viewports, dark mode, retina scale, waits, custom CSS and JavaScript, clicks, hidden selectors, blocked requests, cookies, headers, authorization, timezone and geolocation. It also offers an MCP server for AI agents, async jobs with signed webhooks, bulk capture of up to 100 URLs per call, caching with a chosen TTL, signed links and a usage API.

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo API documentation for parameters and output options.

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com"}, timeout=90)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan. Sign up for the free ScreenshotNeo account to try it without a card.

FAQ

Does an empty Buffer prove Nightmare.js is broken?

No. The documented return type can be correct while Electron captures an empty rectangle or a blank rendering surface. The runtime and window state determine the next test.

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

Should I upgrade Electron immediately?

Not as a first response. Reproduce the issue, record versions and compare visible with hidden or occluded captures. Upgrade or downgrade only as a controlled experiment because the reported failures are tied to particular Electron releases and Windows states.

Can a path argument make the screenshot non-empty?

No. A path changes where the result is written; it does not repair an empty capture. Diagnose the pathless buffer first, then verify the resulting file.

Frequently Asked Questions

How can I tell whether the PNG itself is corrupt?

Write the returned bytes to a file and inspect its decoded dimensions with an image library. A valid non-zero PNG with a blank page indicates rendering or navigation; a zero-size result points toward capture state.

Is minimizing equivalent to hiding a BrowserWindow?

Not necessarily. Electron and the operating system can treat hidden, minimized and fully occluded windows differently. Record the exact state instead of grouping them under one assumption.

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

What is the safest permanent workaround for a platform-specific failure?

Keep a minimal reproduction and pin the known-good Nightmare.js/Electron/OS combination while you evaluate a controlled version change. Avoid applying an issue reporter’s workaround universally.

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.