Express does not capture or render websites by itself. Use an Express route to accept a request, then use a browser automation library such as Puppeteer to open the target page and capture it. The route can return the resulting image as an HTTP response or save it for later use.
How the Express screenshot flow works
Express is the HTTP layer: it handles the incoming request and sends the response. A browser automation library does the rendering and screenshot capture. With Puppeteer, the basic sequence is to launch a browser, create a page, navigate to the website, call page.screenshot(), and close the browser when finished. Puppeteer documents the screenshot API, and its official API guide shows the browser, navigation, capture, and cleanup pattern.
The example below uses Puppeteer and returns a PNG image from an Express endpoint. It takes the target URL from a query parameter, so it is suitable for a trusted internal tool or a controlled set of URLs—not an unrestricted public screenshot service. Deployment security considerations are covered below.
Build a basic Puppeteer screenshot route
1. Install the dependencies
In a new or existing Node.js project, install Express and Puppeteer:
Windows 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 reinstallOutdated 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 match#1 Best Overall
- 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.
npm install express puppeteer
Puppeteer manages a browser installation as part of its normal setup. Browser availability and installation behavior can vary by deployment environment; confirm that the browser can launch in the environment where the server will run.
2. Create the Express server
Save this as server.js. The route accepts a url query parameter, captures the page, and responds with PNG bytes.
const express = require('express');
const puppeteer = require('puppeteer');
const app = express();
const port = process.env.PORT || 3000;
app.get('/screenshot', async (req, res) => {
const targetUrl = req.query.url;
if (typeof targetUrl !== 'string' || targetUrl.length === 0) {
return res.status(400).json({ error: 'Provide a URL in the url query parameter.' });
}
let browser;
try {
const parsedUrl = new URL(targetUrl);
if (!['http:', 'https:'].includes(parsedUrl.protocol)) {
return res.status(400).json({ error: 'Only http and https URLs are supported.' });
}
browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto(parsedUrl.href, { waitUntil: 'networkidle2' });
const image = await page.screenshot({ type: 'png' });
res.set('Content-Type', 'image/png');
res.set('Content-Disposition', 'inline; filename="screenshot.png"');
return res.send(image);
} catch (error) {
console.error('Screenshot capture failed:', error);
return res.status(502).json({ error: 'Could not capture the requested page.' });
} finally {
if (browser) {
await browser.close();
}
}
});
app.listen(port, () => {
console.log(`Screenshot server listening on port ${port}`);
});
Run the server with node server.js, then request http://localhost:3000/screenshot?url=https%3A%2F%2Fexample.com. The browser receives an image response because the route sets Content-Type: image/png. A client that wants to display it can use the endpoint as an image source; a client that wants to save it should write the response body to a file.
What the route is doing
new URL()validates the basic URL syntax and the protocol check limits accepted schemes to HTTP and HTTPS.page.goto()navigates the automated browser. The example waits fornetworkidle2; pages that keep network activity open may not reach this condition promptly, so a different readiness condition or explicit timeout policy may suit a particular site better.page.screenshot()returns image data. Supplying nopathmeans the example can send the bytes directly rather than first writing a local file.- The
finallyblock closes the launched browser after success or error. This simple per-request lifecycle is easy to follow, but launching a browser for every request has startup overhead.
Choose page, full-page, or element capture
By default, a screenshot captures the visible page viewport. Use fullPage: true when the image should include the full document, including content below the fold. Puppeteer also documents capturing a specific element. Its screenshot guide describes page and element capture options.
Capture the full page
Replace the screenshot call with:
const image = await page.screenshot({ type: 'png', fullPage: true });
Full-page output can be substantially taller and larger than a viewport image. Long pages, lazy-loaded images, and pages that only load content as the visitor scrolls may need extra handling before capture. A full-page option alone does not guarantee that every lazy element has been loaded.
Rank #2
- 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.
Capture one element
For a particular component, locate it and screenshot its bounding box:
const element = await page.$('.product-card');
if (!element) {
return res.status(404).json({ error: 'The requested element was not found.' });
}
const image = await element.screenshot({ type: 'png' });
Choose a selector that identifies the intended element on the target page. A selector that matches nothing should be handled explicitly, as above; otherwise, the capture cannot produce the expected element image.
Set output format, quality, and file path
Puppeteer supports screenshot options including output type, path, quality for lossy formats, and full-page capture. PNG is useful when lossless output or transparency matters; JPEG and WebP can reduce file size when appropriate. For JPEG or WebP, set a quality value and choose it according to the visual and bandwidth needs of your application. See the Puppeteer screenshot options for supported option details.
Recommended Free Tools
Return JPEG instead
Capture JPEG and set a matching response content type:
const image = await page.screenshot({ type: 'jpeg', quality: 80 });
res.set('Content-Type', 'image/jpeg');
return res.send(image);
Quality applies to lossy formats. Do not set it when using PNG.
Rank #3
- 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.
Save the image to a file
If the application needs a local artifact rather than a direct response, provide a path:
await page.screenshot({ path: 'screenshot.png', type: 'png', fullPage: true });
Use a controlled destination and filename. If the path is derived from request input, sanitize it and prevent callers from choosing arbitrary filesystem locations. For direct delivery to the requester, returning the screenshot bytes avoids managing an output file.
Use Playwright if it fits your project
Playwright also provides Page.screenshot(), with path, image type, and full-page options. The route architecture remains the same: an Express handler obtains or launches a browser, creates a page, navigates, captures, and returns or stores the image. The exact browser setup and API calls depend on the Playwright package and browser installation used by the project. Consult the Playwright Page screenshot API for its documented options.
The documented capabilities establish that both Puppeteer and Playwright can capture page screenshots and full pages; Puppeteer also documents element capture. The sources cited here do not provide a controlled comparison of performance, hosting cost, or reliability, so choose based on the browser tooling already used by your team, the capture options you need, and the constraints of your deployment rather than assuming one is universally faster or more dependable.
Make the endpoint safe and practical to operate
A route that accepts arbitrary URLs can become a proxy into places the server can reach. URL syntax and protocol checks are not sufficient safeguards for a public endpoint. The documentation cited here does not prescribe a production security policy or deployment limits; those must be designed for the application and its environment. Before exposing this route to untrusted callers, address at least the following:
Rank #4
- 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
- Restrict destinations. Prefer a fixed allowlist of domains or a trusted URL registry. Consider redirects as well as the initial URL, and prevent access to internal services, local addresses, and cloud metadata endpoints.
- Limit resource use. Set request and navigation time limits, constrain concurrent work, and impose practical limits on output dimensions or file size. The appropriate values depend on your infrastructure and must be selected and tested for it.
- Protect the route. Apply authentication and rate controls appropriate to the audience. A public endpoint can otherwise be abused to consume CPU, memory, and outbound bandwidth.
- Manage browser processes. The example starts and closes a browser per request for clarity. At higher request volume, teams may consider reusing a browser and creating isolated pages or contexts, but should verify cleanup, concurrency behavior, and resource usage in their own environment.
- Keep errors useful but restrained. Log operational details on the server, while returning a generic failure to clients so internal paths and infrastructure details are not exposed.
Troubleshoot common screenshot failures
The route returns a 400 error
Check that the request includes exactly one non-empty url parameter and that it is a valid HTTP or HTTPS URL. Encode special characters in the query string. The sample deliberately rejects other protocols.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →The browser will not launch
Confirm that Puppeteer and its browser are installed and that the deployment environment permits the browser process to start. A local development setup and a production container or hosted runtime may not have identical browser dependencies or process permissions.
Navigation hangs or fails
The destination may be unreachable from the server, may redirect, may fail to load, or may keep network requests active so the selected readiness condition is never met. Add an explicit navigation timeout and choose a readiness strategy that matches the site; report a controlled error when navigation fails. Do not assume that a browser timeout means the page itself is broken for every visitor.
The image is blank or incomplete
Some sites render content after initial navigation, require interaction, or load images only when scrolled into view. Wait for a known selector or application-specific readiness signal before capturing, and scroll or otherwise trigger lazy loading if the page requires it. There is no single wait setting that guarantees complete rendering across all websites.
The screenshot is unexpectedly large
Check whether fullPage: true was enabled, whether the document is unusually tall, and whether the chosen image format is appropriate. A viewport capture or lossy format may be better when the consumer does not need every pixel in a lossless full-page image.
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 →Best Value
- 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.
The client displays raw bytes or downloads unexpectedly
Set the correct Content-Type for the captured image and choose an appropriate Content-Disposition. The example uses inline for browser display. Use an attachment disposition if the intended behavior is download.
Or skip the browser setup
If you would rather call a screenshot API than install and operate a browser in Express, ScreenshotNeo accepts one GET request with a URL and returns an image or PDF. Its options include page and full-page capture, element capture, image format, viewport and device settings, and custom CSS or JavaScript. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots, and 1,000 shots a month are free with no card; paid plans start at $5 for 3,000.
For the API details, see the ScreenshotNeo documentation. Here is the one-call cURL example:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesFrequently Asked Questions
Can Express take a website screenshot without a browser library?
No. Express handles HTTP requests and responses; a browser automation library performs the page rendering and image capture.
Can I return the screenshot directly instead of saving it?
Yes. Capture without a file path, set the response content type to the matching image format, and send the returned image bytes.
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.

