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

To make a website download a screenshot when a visitor clicks a button, first determine where the pixels come from. If they are already in a canvas, export the canvas with toBlob(), create a temporary object URL, and trigger an anchor with a download filename. If you need the actual browser display, use getDisplayMedia(); the browser will require the visitor to choose a tab, window, or screen and approve capture. If the target is an arbitrary URL or a server-rendered page, use browser automation or a hosted screenshot service instead of client-side download code.

Download an image that is already rendered in a canvas

This is the simplest and most reliable website implementation. It works for drawing apps, chart exporters, canvas games, image editors, and any page that already owns the pixels in an HTMLCanvasElement.

Minimal PNG download

<button id="downloadScreenshot" type="button">Download screenshot</button>
<canvas id="preview" width="1200" height="800"></canvas>

<script>
const canvas = document.querySelector('#preview');
const button = document.querySelector('#downloadScreenshot');

button.addEventListener('click', () => {
  canvas.toBlob((blob) => {
    if (!blob) {
      throw new Error('Could not encode the screenshot');
    }

    const url = URL.createObjectURL(blob);
    const link = document.createElement('a');
    link.href = url;
    link.download = 'screenshot.png';
    link.textContent = 'Save screenshot.png';
    link.click();

    // Keep the URL alive while the generated file is still usable.
    setTimeout(() => URL.revokeObjectURL(url), 1000);
  }, 'image/png');
});
</script>

toBlob() encodes the canvas asynchronously. PNG support is required, and PNG is also the fallback when an unsupported or omitted type is requested. The anchor’s download value is a suggested filename, not a command that can override browser settings. A browser may save automatically, ask the visitor where to save, or open the resource according to its configuration.

Offer JPEG or WebP

Pass a MIME type and, for lossy formats, a quality value between 0 and 1:

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.
canvas.toBlob((blob) => {
  if (!blob) return;
  const url = URL.createObjectURL(blob);
  const link = document.createElement('a');
  link.href = url;
  link.download = 'screenshot.webp';
  link.click();
  // Revoke after the link is no longer needed.
  setTimeout(() => URL.revokeObjectURL(url), 1000);
}, 'image/webp', 0.9);

Use PNG when text, line art, transparency, or exact pixel reproduction matters. JPEG is appropriate for photographic content but does not preserve transparency. WebP can reduce file size when the visitor’s browser supports it; retain a PNG fallback if format compatibility is important.

Keep a visible link when another click may be required

Some browsers or download policies may not complete a synthetic click exactly as expected. For generated files that should remain available, append a visible link instead of immediately removing it:

canvas.toBlob((blob) => {
  if (!blob) return;
  const url = URL.createObjectURL(blob);
  const link = document.createElement('a');
  link.href = url;
  link.download = 'screenshot.png';
  link.textContent = 'Download the screenshot';
  document.querySelector('#downloads').replaceChildren(link);
  // Revoke only when you remove the link from the interface.
}, 'image/png');

Why toBlob() is preferable to toDataURL()

toDataURL() turns the whole image into a long string. Large canvases can consume considerable memory, create expensive string copies, and run into URL-length limits. toBlob() produces binary data and an object URL, which is a better fit for large screenshots. Release each object URL with URL.revokeObjectURL() after the user can no longer open or save that file; revoking it immediately after click() can make the download unreliable.

Capture the live browser display with getDisplayMedia()

Use the Screen Capture API when the required image is the pixels currently displayed in a selected tab, window, or monitor rather than content your page has drawn itself. This is not a silent screenshot function. The browser presents a source picker, requires permission, and may reject calls that are not made after a recent user interaction. It also requires a secure context such as HTTPS, and availability varies by browser and device.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Capture one frame and download it

async function captureDisplayFrame() {
  const stream = await navigator.mediaDevices.getDisplayMedia({
    video: true,
    audio: false
  });

  const track = stream.getVideoTracks()[0];
  try {
    const imageCapture = new ImageCapture(track);
    const bitmap = await imageCapture.grabFrame();
    const canvas = document.createElement('canvas');
    canvas.width = bitmap.width;
    canvas.height = bitmap.height;
    canvas.getContext('2d').drawImage(bitmap, 0, 0);

    canvas.toBlob((blob) => {
      if (!blob) throw new Error('Could not encode the captured frame');
      const url = URL.createObjectURL(blob);
      const link = document.createElement('a');
      link.href = url;
      link.download = 'display-screenshot.png';
      link.textContent = 'Download display screenshot';
      document.querySelector('#downloads').replaceChildren(link);
      // Keep the URL while the visible link remains available.
    }, 'image/png');

    bitmap.close();
  } finally {
    stream.getTracks().forEach((captureTrack) => captureTrack.stop());
  }
}

document.querySelector('#captureDisplay').addEventListener('click', () => {
  captureDisplayFrame().catch((error) => {
    console.error(error);
    // Show a cancel, permission, or unsupported-browser message in the UI.
  });
});

Call this function from a clearly labeled button. Explain what will be captured and provide a cancel path. The visitor chooses the source; a site cannot use constraints to silently narrow that choice. Do not confuse this ordinary webpage API with extension-only tab-capture capabilities or browser DevTools commands.

When canvas export fails: origin-clean rules

A canvas becomes tainted when it contains pixels from another origin that were loaded without permission for readback. Once tainted, calls such as toBlob() and toDataURL() throw a SecurityError. Configure the remote server to send suitable CORS response headers and request the image with the matching cross-origin mode before drawing it:

const image = new Image();
image.crossOrigin = 'anonymous';
image.onload = () => {
  const canvas = document.querySelector('#preview');
  canvas.getContext('2d').drawImage(image, 0, 0);
};
image.src = 'https://assets.example.com/photo.png';

The server at assets.example.com must explicitly permit your page’s origin (or use an appropriate public CORS policy). Setting crossOrigin in JavaScript cannot create permission that the server did not grant.

Why a direct URL usually cannot be downloaded as a website screenshot

An anchor can suggest downloading a same-origin HTTP resource or a generated blob: or data: URL. It cannot force an arbitrary cross-origin page URL to become a screenshot. A URL such as https://example.com is HTML, not a bitmap, and browser security rules prevent a normal page from reading another site’s rendered pixels.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Choose one of these architectures instead:

  • Your own page: render the content into a canvas and export that canvas.
  • Visitor’s current display: request getDisplayMedia() and let the visitor select a source.
  • Arbitrary URL or HTML: run a browser automation worker or call a hosted screenshot endpoint. This is suitable for previews, reports, monitoring, and server-side jobs.
  • Manual development work: use browser DevTools. Firefox, for example, documents saving screenshots of selected nodes; this is a developer workflow, not a feature silently available to site visitors.

Performance and reliability checklist

  • Use toBlob() rather than building large data URLs.
  • Choose an output format and dimensions appropriate to the use case; a very large canvas can require substantial memory during encoding.
  • Disable the capture button or show progress while an asynchronous encode is running, so users do not start duplicate jobs.
  • Keep the generated object URL alive for every visible link and revoke it when that link is removed.
  • Handle a null Blob and display an actionable error instead of assuming encoding succeeded.
  • Expect browser prompts and settings to affect filenames and save behavior.
  • For display capture, test secure-context requirements, permission denial, source-picker cancellation, and unsupported browsers.
  • Never promise identical behavior across desktop, mobile, and every browser without testing the exact target matrix.

Common errors and fixes

“SecurityError” from toBlob()

The canvas is not origin-clean, usually because a remote image or video lacked CORS permission. Configure response headers on the asset server, set crossOrigin before assigning src, and redraw onto a fresh canvas after the policy is corrected.

The download opens instead of saving

The download attribute is a hint. Browser preferences, content-disposition headers, and security policy can change the result. Keep a visible same-origin or Blob link and tell users where the browser may save the file.

The generated file is empty or corrupt

Wait for the toBlob() callback, check for a null Blob, and do not revoke the object URL until the link is no longer usable. If the canvas is still being drawn, export only after rendering completes.

getDisplayMedia() rejects immediately

Make the call from a recent user gesture, serve the page over HTTPS, verify that the browser supports the API, and distinguish cancellation from permission denial in your error message.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

Only part of the page appears

Canvas export captures the canvas bitmap, not the surrounding DOM. Display capture captures the selected visible surface, not an automatically expanded, full-length webpage. For a full-page URL image, use a server-side browser or screenshot service.

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

Or skip the browser setup

When the input is a URL rather than an image already in your page, ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns PNG, JPEG, WebP, or PDF. It accepts cookies and consent banners like a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status.

See the complete parameter reference in the ScreenshotNeo documentation. A basic cURL request is:

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

Python:

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

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}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const data = Buffer.from(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('shot.webp', data));

For AI workflows, its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients. Other useful options include full-page lazy-image loading, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF paper and page controls, custom CSS and JavaScript, clicks, selector or network-idle waits, ad and tracker blocking, custom headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, configurable caching, signed public-image links, asynchronous webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Parameter names used by other screenshot APIs also work, which can simplify migration.

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.

The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is included on every plan, and yearly billing provides two months free. Create a free ScreenshotNeo account to start.

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.

Frequently Asked Questions

Can JavaScript take a screenshot of any webpage without permission?

No. A page can export pixels it owns, or request a user-approved display capture. An arbitrary URL requires a server-side browser or screenshot service.

Should I use PNG, JPEG, or WebP?

Use PNG for text, line art, and transparency; JPEG for photographs without transparency; WebP when smaller files are useful and your compatibility requirements allow it.

Why does my downloaded filename differ from the value in link.download?

The property is a filename suggestion. Browser preferences, prompts, and response headers can influence the final name and handling.

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

Can a canvas export include content outside the canvas element?

No. Canvas export contains only that bitmap. Capturing the surrounding DOM or a complete URL requires display capture or browser automation.

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.