Use Bun’s built-in fetch to send a screenshot request, then pass the binary response to Bun.write to save it. You do not need Puppeteer for a one-shot capture: the example below calls Browserless’s hosted /screenshot endpoint. For a capture that needs clean-up of consent banners and popups, the ScreenshotNeo option later in this guide makes a single GET request instead.
Take a screenshot in Bun with Browserless
This example sends a URL and screenshot options as JSON, checks for an HTTP error, and writes the image response to screenshot.png. Bun’s fetch implements the WHATWG Fetch API, and Bun.write can write a response body directly to disk. Browserless documents the request as a POST to /screenshot with a URL and optional Puppeteer-style options.
const token = Bun.env.BROWSERLESS_TOKEN;
if (!token) throw new Error("Set BROWSERLESS_TOKEN");
const response = await fetch(
`https://production-sfo.browserless.io/screenshot?token=${encodeURIComponent(token)}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
"Cache-Control": "no-cache"
},
body: JSON.stringify({
url: "https://example.com",
options: { fullPage: true, type: "png" }
})
}
);
if (!response.ok) {
throw new Error(`Screenshot failed: ${response.status} ${await response.text()}`);
}
await Bun.write("screenshot.png", response);
console.log("Saved screenshot.png");
Set BROWSERLESS_TOKEN in the environment where this Bun program runs. Do not put a real token in a source file, browser bundle, or public repository. The endpoint above is the documented endpoint used in this example; check your provider account’s instructions for the endpoint and credentials to use with your own account.
Run it
- Save the code as
screenshot.ts. - Set the environment variable in your shell, substituting your token. For example, in a POSIX shell:
export BROWSERLESS_TOKEN='your-token'. - Run
bun run screenshot.ts. - On a successful response, look for
screenshot.pngin the current working directory.
Keep the target URL on HTTPS where possible. The program checks the provider’s HTTP status before writing the file, so a provider error is reported rather than silently saved with a PNG extension.
Capture inline HTML instead of a URL
For a small page you generate yourself, send an html field in place of url. Browserless warns not to send both fields in the same request.
#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.
const token = Bun.env.BROWSERLESS_TOKEN;
if (!token) throw new Error("Set BROWSERLESS_TOKEN");
const response = await fetch(
`https://production-sfo.browserless.io/screenshot?token=${encodeURIComponent(token)}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
html: "<html><body><h1>Hello from Bun</h1></body></html>",
options: { fullPage: true, type: "png" }
})
}
);
if (!response.ok) throw new Error(await response.text());
await Bun.write("inline.png", response);
This is useful for rendering generated markup without first deploying it at a public URL. If the HTML references remote images, fonts, or stylesheets, those resources still have to be reachable from the service performing the capture.
Choose the capture options you need
Browserless accepts screenshot options modeled on Puppeteer. Use explicit settings so the same request is less likely to produce different output just because a default changed.
| Need | Request setting | What it does |
|---|---|---|
| Capture the whole page | options: { fullPage: true } |
Requests a full-page image rather than only the initial viewport. |
| Choose an image format | options: { type: "png" } |
Set type to the desired supported format: PNG, JPEG, or WebP. Add a quality setting where the provider supports it. |
| Capture a particular element | selector: "..." at the top level |
Waits for the selected element and crops the capture to its bounds. |
| Capture a fixed rectangle | options: { clip: { x, y, width, height } } |
Limits the screenshot to the specified rectangle. |
| Expose lazy-loaded content | scrollPage: true at the top level, usually with options.fullPage: true |
Scrolls the page before the full-page capture, which can prompt content and images to load. |
For example, a JPEG full-page capture can use { url: "https://example.com", scrollPage: true, options: { fullPage: true, type: "jpeg" } }. Confirm the accepted format spelling and any quality option against your provider’s current documentation if you need exact encoding behavior.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteRank #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.
Element and rectangle captures
Use a selector when the target is a semantic page element such as a product card or chart. Use clip when the crop is defined by coordinates instead. These approaches solve different problems: selectors follow the element’s rendered bounds, while a fixed rectangle is tied to the page’s layout and viewport coordinates. A selector that never appears can prevent a useful image from being returned, so check that it exists at capture time.
Full-page and lazy-loaded content
A full-page option expands the capture beyond the visible viewport, but it does not guarantee every site has rendered every image before capture. For pages that load content as the visitor scrolls, combine scrollPage: true with full-page capture. For more involved readiness conditions, such as waiting for a particular state after an interaction, a browser connection gives more control than a one-shot REST request.
Serve the screenshot from a Bun API
A Bun server can accept a URL from a caller, request the capture upstream, and return the resulting image bytes. The example validates that the input begins with HTTPS, keeps the provider token on the server, and forwards a failed upstream response status rather than presenting it as an image.
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.
Bun.serve({
async fetch(req) {
const input = await req.json() as { url?: string };
if (!input.url || !/^https:///.test(input.url)) {
return Response.json({ error: "https URL required" }, { status: 400 });
}
const token = Bun.env.BROWSERLESS_TOKEN;
if (!token) return Response.json({ error: "Screenshot provider is not configured" }, { status: 500 });
const capture = await fetch(
`https://production-sfo.browserless.io/screenshot?token=${encodeURIComponent(token)}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ url: input.url, options: { fullPage: true, type: "png" } })
}
);
if (!capture.ok) {
return new Response(await capture.text(), { status: capture.status });
}
return new Response(await capture.arrayBuffer(), {
headers: { "Content-Type": capture.headers.get("content-type") ?? "image/png" }
});
}
});
URL validation is important when an endpoint accepts caller-supplied destinations: a scheme check is only a basic guard, not a complete access-control policy. If this API is exposed beyond a trusted application, restrict which hosts callers may request and apply your own authentication and rate limits. Avoid logging submitted page contents, cookies, authorization headers, or provider credentials.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Or skip the browser setup
ScreenshotNeo takes a screenshot with one GET request and returns an image or PDF. The request below saves a WebP capture of the example page; create an API key and keep it server-side.
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 API documentation for request parameters. It removes cookie and consent banners, newsletter popups, and chat widgets before capture; each of those clean-up steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots.
Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card required.
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
When to use REST and when to use a browser connection
A hosted screenshot REST call is a good fit when a job needs one capture from a URL or a piece of HTML. It avoids installing and managing a local browser and returns the image as an ordinary HTTP response.
Recommended Free Tools
Choose a Playwright or Puppeteer browser connection when the capture depends on a sequence of actions or state, such as clicking through a flow, waiting for a specific UI change, or managing cookies across navigation. Browserless documents both one-shot REST calls and browser connections; a browser session gives code control over the interactions before taking the screenshot, while a REST request is simpler when the page can be captured in one operation.
ScreenshotOne is another hosted option: its documentation describes GET and POST forms at /take and access-key authentication. Before choosing any provider, compare the endpoint shape, URL versus HTML input, formats and capture options, authentication placement, quota and pricing, regions, timeout behavior, and data-retention terms. The information available here does not establish current quotas, prices, or regional availability for Browserless or ScreenshotOne, so check those details with the providers before committing.
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.
Reliability, performance, and cost considerations
- Bound request time. A target page or upstream service can be slow. Bun’s Fetch supports standard cancellation patterns such as
AbortSignal.timeout(...); choose a timeout appropriate to your workload and handle the resulting failure rather than leaving requests unbounded. - Keep output predictable. Specify format and full-page behavior instead of relying on defaults. Use scrolling for lazy-loaded pages and a selector or clip only when the crop is intentional.
- Preserve useful errors. Check
response.okbefore saving bytes. During development, retaining upstream error text makes authentication, request-shape, and provider failures easier to diagnose. In a public API, avoid returning sensitive upstream details to untrusted callers. - Account for page variability. A screenshot is dependent on the page’s own load behavior and the capture service’s ability to retrieve it. A timeout or failed load is not fixed simply by changing PNG to JPEG; identify whether the delay is in the target page, a required resource, or the provider request.
- Estimate spend from actual usage. A screenshot endpoint may meter captures or impose plan limits. Verify the current plan terms and how unsuccessful captures are treated before sending bulk workloads; do not infer cost from image format or assume a failed request is free.
Troubleshooting common Bun screenshot failures
| Symptom | Likely cause | What to check |
|---|---|---|
| The program stops with “Set BROWSERLESS_TOKEN” | The environment variable is missing in the process running Bun. | Export the variable in the same shell or configure it in the runtime environment, then restart the process. |
| The provider returns a non-success status | The token, endpoint, JSON body, or provider-side access may be wrong. | Inspect the status and upstream error text during development. Confirm the account token and request format with the provider. |
| The response is not a readable image | Error content may have been written or forwarded as if it were image data. | Check response.ok before Bun.write; preserve the upstream status in your Bun server. |
| The full page misses images or sections | Content may load only after scrolling or after a later UI state. | Try scrollPage: true together with fullPage: true. For interactive or stateful pages, use a browser connection and wait for the required state. |
| An element capture fails or is empty | The selector may not match an element at capture time. | Verify the selector in the target page and confirm the element is rendered before capture. |
| Inline HTML request is rejected or behaves unexpectedly | The body may contain both html and url, or remote assets may be inaccessible. |
Send one input mode, not both, and confirm referenced resources can be reached by the capture service. |
| Requests hang or take too long | The target, its resources, or the provider may be slow or unavailable. | Set an explicit timeout with an abort signal, surface timeout failures clearly, and retry only when it makes sense for the job. |
FAQ
Can Bun save a screenshot response without converting it to a buffer?
Yes. The quick-start example passes the successful Response directly to Bun.write, which writes its body to a file.
Can I use a screenshot API without Puppeteer?
Yes. A one-shot REST endpoint can render a URL or HTML and return image bytes. Puppeteer or Playwright is useful when your code must operate a browser through multiple steps before capture.
Free tools Windows power users keep installed
One-click scans. No signup required.
Is this code suitable for a browser-facing Bun app?
Keep the provider credential on a server you control. If a browser client needs screenshots, have it call your Bun endpoint rather than exposing the provider token in client-side code.
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.

