Use Nightmare’s error-first screenshot callback to receive a PNG Buffer, confirm a file write, or capture a clipped rectangle. The overload you choose determines what the callback receives: .screenshot(done) returns image bytes, while .screenshot(path, done) writes the PNG and calls you after the write. Add a clip object when you need only part of the visible page.
What the NightmareJS screenshot callback returns
Nightmare documents .screenshot([path][, clip]). Both arguments are optional, and output is always PNG. Without a path, the action resolves to a Node.js Buffer. With a path, Nightmare writes that buffer to disk and the callback signals completion; it does not pass the image buffer as the callback’s second value.
The callback form follows Nightmare’s error-first convention: done(err, value). For an in-memory capture, value is the PNG buffer. For a path capture, handle err and treat successful return as confirmation that the file write completed.
Nightmare’s action implementation is effectively screenshot(path, clip, done). If the first argument is a function, it is treated as the callback. If the second argument is a function, it becomes the callback and the first argument is interpreted as either a path or a clip object. When a child capture returns image data, Nightmare converts it to a Node buffer before resolving the action.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
- Compatible with Nintendo Switch 2’s new GameChat mode
- Auto-Light Balance: RightLight boosts brightness by up to 50%, reducing shadows so you look your best—compared to previous-generation Logitech webcams (1)
- Privacy with a Slide: The integrated webcam cover makes it easy to get total, reliable privacy when you're not on a video call
- Built-In Mic: The built-in microphone lets others hear you clearly during video calls
- Easy Plug-And-Play: The Brio 101 works with most video calling platforms, including Microsoft Teams, Zoom and Google Meet—no hassle; it just works
Prerequisites and lifecycle
- Install Nightmare in a Node.js project and pin the version used by your application. Nightmare’s repository is in Segment’s boneyard and is marked no longer maintained, so it is a legacy API; assess maintained alternatives before starting new automation.
- Call
.screenshot(...)after navigation and any required waits. A selector wait such as.wait('body')prevents a capture from racing the initial page load. - Keep
.end()after the screenshot action in the queued chain, or await the screenshot promise before closing the browser.
The examples below use CommonJS and the documented callback overloads. They assume the page is reachable and that your process can write to the selected directory.
Get a screenshot Buffer with .screenshot(done)
Omit the path when your program needs to inspect, upload, transform, or otherwise handle the PNG in memory. The callback receives (err, buffer).
const Nightmare = require('nightmare')
const nightmare = Nightmare()
nightmare
.goto('https://example.com')
.wait('body')
.screenshot((err, buffer) => {
if (err) return console.error(err)
console.log('PNG bytes:', buffer.length)
// buffer is a Node.js Buffer containing PNG data
})
.end()
.then(() => console.log('browser closed'))
.catch(console.error)
The callback runs after the capture has produced the image data. If you need to pass the bytes to another function, do it inside the success branch or return a promise from the surrounding workflow. Do not expect a file path to be created by this overload.
Write a PNG with .screenshot(path, done)
Supply a path when Nightmare should save the image itself. The callback is still error-first, but a successful callback does not provide the buffer as its second argument.
const Nightmare = require('nightmare')
const nightmare = Nightmare()
nightmare
.goto('https://example.com')
.wait('body')
.screenshot('/tmp/example.png', err => {
if (err) return console.error('Screenshot failed:', err)
console.log('saved /tmp/example.png')
})
.end()
.then(() => console.log('browser closed'))
.catch(console.error)
Nightmare invokes the callback after its file write completes. Ensure the parent directory exists and that the process has permission to create or replace the file.
Rank #2
- Compatible with Nintendo Switch 2’s new GameChat mode
- Crisp HD 720p/30 fps video calls with diagonal 55° field of view and auto light correction. Compatible with popular platforms including Skype and Zoom.
- The built-in noise-reducing mic makes sure your voice comes across clearly up to 1.5 meters away, even if you’re in busy surroundings.
- C270’s RightLight 2 feature adjusts to lighting conditions, producing brighter, contrasted images to help you look good in all your conference calls.
- The adjustable universal clip lets you attach the camera securely to your screen or laptop, or fold the clip and set the webcam on a shelf. You’re always ready for your next video call.
Use a clip rectangle
A clip limits the capture to a rectangle in the visible capture context. The rectangle follows Electron capture semantics, so its coordinates are relative to the page view rather than an arbitrary document coordinate system. A typical clip object contains x, y, width, and height.
Clip into memory
const Nightmare = require('nightmare')
const nightmare = Nightmare()
const clip = { x: 80, y: 120, width: 640, height: 360 }
nightmare
.goto('https://example.com')
.wait('body')
.screenshot(clip, (err, buffer) => {
if (err) return console.error(err)
console.log('clipped PNG bytes:', buffer.length)
})
.end()
.catch(console.error)
This two-argument form is readable when the first value is clearly an object and the second is a function. If your code also supplies a path, use the four-argument form to remove ambiguity.
Clip directly to a file
const Nightmare = require('nightmare')
const nightmare = Nightmare()
const clip = { x: 80, y: 120, width: 640, height: 360 }
nightmare
.goto('https://example.com')
.wait('body')
.screenshot('/tmp/example-card.png', clip, err => {
if (err) return console.error('Clipped capture failed:', err)
console.log('saved clipped image')
})
.end()
.catch(console.error)
.screenshot(path, clip, done) is the clearest overload when both options are present: the string is the destination, the object is the rectangle, and the function is the completion callback.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Promise-style Nightmare code
Nightmare wraps callback results in a native promise that resolves one value. In modern code, you can omit the callback and handle the returned buffer in the next .then().
const Nightmare = require('nightmare')
const fs = require('fs')
const nightmare = Nightmare()
nightmare
.goto('https://example.com')
.wait('body')
.screenshot()
.then(buffer => {
// buffer contains PNG image data
fs.writeFileSync('/tmp/example.png', buffer)
})
.end()
.then(() => console.log('browser closed'))
.catch(console.error)
Promise style changes sequencing and error handling, not the image format or clipping behavior. A path still means Nightmare performs the file write; no path still means the next promise handler receives a buffer.
Rank #3
- 【Full HD 1080P Webcam】Powered by a 1080p FHD two-MP CMOS, the NexiGo N60 Webcam produces exceptionally sharp and clear videos at resolutions up to 1920 x 1080 with 30fps. The 3.6mm glass lens provides a crisp image at fixed distances and is optimized between 19.6 inches to 13 feet, making it ideal for almost any indoor use.
- 【Wide Compatibility】Works with USB 2.0/3.0, no additional drivers required. Ready to use in approximately one minute or less on any compatible device. Compatible with Mac OS X 10.7 and higher / Windows 7, 8, 10 & 11 / Android 4.0 or higher / Linux 2.6.24 / Chrome OS 29.0.1547 / Ubuntu Version 10.04 or above. Not compatible with XBOX/PS4/PS5.
- 【Built-in Noise-Cancelling Microphone】The built-in noise-canceling microphone reduces ambient noise to enhance the sound quality of your video. Great for Zoom / Facetime / Video Calling / OBS / Twitch / Facebook / YouTube / Conferencing / Gaming / Streaming / Recording / Online School.
- 【USB Webcam with Privacy Protection Cover】The privacy cover blocks the lens when the webcam is not in use. It's perfect to help provide security and peace of mind to anyone, from individuals to large companies. 【Note:】Please contact our support for firmware update if you have noticed any audio delays.
- 【Wide Compatibility】Works with USB 2.0/3.0, no additional drivers required. Ready to use in approximately one minute or less on any compatible device. Compatible with Mac OS X 10.7 and higher / Windows 7, 10 & 11, Pro / Android 4.0 or higher / Linux 2.6.24 / Chrome OS 29.0.1547 / Ubuntu Version 10.04 or above. Not compatible with XBOX/PS4/PS5.
Callback versus promise: which should you choose?
| Concern | Callback style | Promise style |
|---|---|---|
| Output | No path: Buffer; path: write completion |
No path: resolved Buffer; path: resolved action after write |
| Sequencing | Work inside done(err, value) |
Work in the following .then(value => ...) |
| Error handling | Check if (err) first |
Attach .catch() |
| Clipping | Pass a clip object in either overload | Pass the clip object before awaiting the action |
| Browser lifecycle | Queue .end() after capture |
Await or return the capture before calling .end() |
Use callbacks when integrating with an existing error-first API or when the completion point is naturally local. Use promises when several asynchronous operations must be composed, but retain the same lifecycle rule: the browser must remain open until the screenshot action has finished.
Common callback problems and fixes
The callback receives no buffer
Check whether a path was supplied. With .screenshot('/tmp/a.png', done), the callback is a file-write completion callback and does not receive PNG bytes as its second value. Remove the path and use .screenshot(done) when you need a buffer, or read the completed file explicitly.
The callback never fires or the process exits early
Do not close Nightmare before the queued screenshot runs. Keep .end() after .screenshot(...), and return or await the chain if it is inside another asynchronous function. Also attach .catch(console.error) so a rejected action is not hidden.
The wrong overload is being selected
Nightmare identifies functions as callbacks. A clip must therefore be an object, not a function or an accidentally undefined variable. Prefer .screenshot(path, clip, done) when all three values are used; it makes the intended argument roles explicit.
The crop is empty or shifted
The rectangle is measured against the visible capture context. Coordinates that describe document space can miss the target when the page is scrolled. Compute the element’s bounds, scroll it into view first, and then capture. Verify that width and height are positive and that the rectangle lies inside the current viewport.
Rank #4
- 1080P Webcam with Cover for Video Calls - EMEET computer webcam provides design and Optimization for professional video streaming. Realistic 1920 x 1080p video, 5-layer anti-glare lens, providing smooth video. C960 computer camera delivers 1920x1080 video with fixed focus (11.8–118.1 inches), so as to provide a clearer image. C960 USB webcam has a cover and can be removed automatically to meet your needs for privacy. For optimal image performance, use the webcam in a well-lit environment.
- Built-in 2 Omnidirectional Mics - EMEET webcam with microphone for desktop features 2 built-in omnidirectional microphones, picking up your voice to create clear audio for communication. When installing the webcam, select EMEET C960 as the default microphone input device in your computer and video applications and select C960 as the default device in Zoom/Teams and ensure microphone permissions are enabled for proper use. Please note that C960 does not include built-in speakers.
- Automatic Light Adjustment - Automatic exposure adjustment is applied in EMEET HD webcam 1080p so that the streaming webcam can deliver stable image performance. EMEET C960 camera for computer also features color adjustment and exposure optimization to help you look your best. For optimal video quality, it is recommended to use the webcam in normal or well-lit environments and select suitable video settings in your application. Proper lighting helps achieve a clearer and more balanced image.
- Plug-and-Play & Upgraded USB Connectivity - New C960 webcam features both USB Type-A & A-to-C adapter connections for wider compatibility. For stable performance, connect the webcam directly to the computer's main USB port and ensure the device is recognized correctly. If a hub or docking station is used, please ensure it provides sufficient power and stable data transmission, as limited ports may affect performance. 90° wide-angle lens captures more participants without frequent adjustments.
- High Compatibility & Multi Application - C960 webcam for laptop is compatible with Windows 10/11, macOS 10.14+, and Android TV 7.0+. Not supported: Windows Hello, TVs, tablets, or game consoles. It works with Zoom, Teams, Facetime, Google Meet, YouTube and more. Please select C960 webcam as the default camera and microphone device in your application and ensure camera/microphone permissions are enabled, especially on macOS. (Tips: Incompatible with Windows Hello)
An error is ignored
Always return after handling an error in a callback:
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 matchPC 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 & 11.screenshot((err, buffer) => {
if (err) return console.error('capture failed:', err)
// safe to use buffer here
})
In promise code, put the chain’s failure path in .catch(). Navigation failures, renderer problems, invalid clip values, and filesystem errors should be treated as normal failure cases rather than assumed impossible.
Make captures more reliable
- Wait for meaningful content: use
.wait('body')for a basic readiness check, or wait for the selector that proves the component you need has rendered. - Control timing: if content appears after JavaScript execution, add an appropriate wait before the screenshot rather than capturing immediately after
.goto(). - Keep destinations deterministic: use absolute paths or resolve paths with Node’s
pathmodule, and create the output directory before starting the browser. - Validate buffers: check that the value is a
Bufferand that its length is greater than zero before uploading or storing it. - Pin legacy dependencies: because Nightmare is no longer maintained, lock versions and test Electron/Node compatibility in the environment where captures run.
Or skip the browser setup
ScreenshotNeo provides a website screenshot API when you want one HTTP request instead of managing Nightmare and Electron. The request below returns an image response; the URL is URL-encoded by the command.
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 request options and response details. The same capture can be made from Python:
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)
Or 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}`);
Before capture, ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and whether the request was billed. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots; every feature is available on every plan, and yearly billing provides two months free. Create a free ScreenshotNeo account to start without a card.
Best Value
When to keep Nightmare and when to switch
Keep Nightmare when you are maintaining an existing test or automation suite whose callback and Electron behavior are already understood. Its callback overloads are small and useful for local, in-process captures. For new services, compare the maintenance risk of a boneyard project with an HTTP screenshot API: an API removes browser-process lifecycle work, while Nightmare gives you direct control over an interactive browser queue. Make that choice based on your deployment, authentication, rendering needs, and tolerance for pinning legacy dependencies.
FAQ
Does Nightmare return JPEG or WebP from .screenshot()?
No. Nightmare’s documented screenshot output is always PNG, regardless of whether you receive a buffer or save a file.
Can I receive both a saved file and the buffer in one callback?
Not from the path overload. Save with a path and read the file after successful completion, or omit the path, receive the buffer, and write it yourself.
Is a clip rectangle full-page?
No. A clip captures only the specified rectangle in the visible capture context. It is not a substitute for stitching or full-page scrolling capture.
What does the callback’s first argument mean?
It is the error value. Check it before using the second argument; on a path capture, successful completion generally has no image value to consume.
Frequently Asked Questions
Does Nightmare return JPEG or WebP from .screenshot()?
No. Nightmare’s screenshot output is always PNG.
Can I receive both a saved file and the buffer in one callback?
Not from the path overload. Read the file after it succeeds, or omit the path and write the returned buffer yourself.
Is a clip rectangle full-page?
No. It captures the specified rectangle in the visible capture context.
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 errorsWhat does the callback’s first argument mean?
It is the error value; check it before using the second argument.
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.

