Recommended Free Tools
To capture a browser window after a button click, call navigator.mediaDevices.getDisplayMedia() inside the click handler, let the user choose and approve a window or other display surface, then grab one video frame and save it as a PNG. The API returns a live media stream, not an image. This approach requires the user’s permission each time and cannot silently capture an arbitrary browser window.
What the browser can capture—and what it cannot
The Screen Capture API lets a web page request permission to capture a display surface. The browser presents its own picker, where the user chooses an available source such as a window, tab, or screen. The exact choices and picker presentation depend on the browser and operating system. The page cannot use JavaScript to silently select a particular window or bypass that picker.
In this article, “browser window screenshot” means a still image of a surface the user selected in the browser’s screen-sharing prompt. It is not the same as capturing the current page’s DOM, and it does not guarantee that the chosen surface is an entire browser window. If you need a specific page element, see Element Capture and Region Capture; those APIs have additional support requirements.
Build the button and download flow
Use a secure context (typically HTTPS, or localhost during development), give the user a clear explanation of what the button does, and call getDisplayMedia() directly from the click event. The example below captures one frame, encodes it as PNG, starts a download, and stops the capture tracks even when something fails.
#1 Best Overall
- Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
- Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
- Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
- Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
- Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)
HTML
<button id="capture" type="button">Capture screenshot</button>
<p id="status" role="status" aria-live="polite"></p>
<a id="download" hidden>Download screenshot</a>
JavaScript
const button = document.querySelector("#capture");
const downloadLink = document.querySelector("#download");
const status = document.querySelector("#status");
let previousUrl;
button.addEventListener("click", async () => {
button.disabled = true;
status.textContent = "Choose a window, tab, or screen in the browser prompt.";
let stream;
let bitmap;
try {
// Must be called while handling the user's click.
stream = await navigator.mediaDevices.getDisplayMedia({
video: { displaySurface: "window" },
audio: false,
});
const [track] = stream.getVideoTracks();
if (!track) throw new Error("The selected source has no video track.");
const imageCapture = new ImageCapture(track);
bitmap = await imageCapture.grabFrame();
const canvas = document.createElement("canvas");
canvas.width = bitmap.width;
canvas.height = bitmap.height;
const context = canvas.getContext("2d");
if (!context) throw new Error("Could not create a canvas context.");
context.drawImage(bitmap, 0, 0);
const blob = await new Promise((resolve) => {
canvas.toBlob(resolve, "image/png");
});
if (!blob) throw new Error("Could not encode screenshot.");
if (previousUrl) URL.revokeObjectURL(previousUrl);
previousUrl = URL.createObjectURL(blob);
downloadLink.href = previousUrl;
downloadLink.download = "screenshot.png";
downloadLink.hidden = false;
downloadLink.click();
status.textContent = "Screenshot captured. If it did not download, use the download link.";
} catch (error) {
console.error("Screenshot capture failed:", error);
if (error.name === "NotAllowedError") {
status.textContent = "Capture was cancelled or permission was not granted.";
} else {
status.textContent = `Screenshot failed: ${error.message || error.name}`;
}
} finally {
stream?.getTracks().forEach((track) => track.stop());
bitmap?.close();
button.disabled = false;
}
});
This follows the sequence documented by MDN’s capture-and-download example, while omitting its optional element-restriction steps. The ImageCapture API is not supported everywhere, so check the compatibility of both it and getDisplayMedia() against your target browsers before shipping.
Why each step matters
Start from a real user action
getDisplayMedia() requires transient user activation. Call it from the button handler, not from page-load code, a timer, or a delayed background task. It can reject if the call is not associated with a user gesture. The user must be prompted for permission every time; there is no durable grant that lets a site capture later without asking.
Rank #2
- Pair and Play: With fast, easy Bluetooth wireless technology, you’re connected in seconds to this quiet cordless mouse —no dongle or port required
- Less Noise, More Focus: Silent mouse with 90% reduced click sound and the same click feel, eliminating noise and distractions for you and others around you (1)
- Long-Lasting Battery Life: Up to 18-month battery life with an energy-efficient auto sleep feature, so you can go longer between battery changes (2)
- Comfortable, Travel-Friendly Design: Small enough to toss in a bag; this slim and ambidextrous portable compact mouse guides either your right or left hand into a natural position
- Long-Range: Reliable, long-range Bluetooth wireless mouse works up to 10m/33 feet away from your computer (3)
Treat the picker result as a live stream
The returned MediaStream contains a video track. ImageCapture.grabFrame() turns one moment from that track into an ImageBitmap. Drawing the bitmap onto a canvas and calling toBlob() produces an image file payload. If you want to show a preview instead of downloading immediately, set an img element’s src to the object URL and provide an explicit save button.
Release resources promptly
Stopping every stream track in finally ends capture after the still is obtained, including on encoding or download errors. Close the bitmap when finished, and revoke an older object URL before replacing it. If you keep a preview on screen, retain its URL until the preview is replaced or removed, then call URL.revokeObjectURL().
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 →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Rank #3
- 【Dual Mode Wireless Bluetooth Mouse】: Switch easily between two devices—connect one via Bluetooth (BT5.2/3.0) and the other using a 2.4G USB receiver. No drivers needed; just plug and play. Enjoy a reliable connection up to 33 feet. Note: You can't use both modes simultaneously; the USB receiver is stored in the mouse.
- 【Rechargeable Wireless Mouse】: Equipped with a 500mAh lithium-ion battery, it charges in 2 hours for over 7 days of use and 30 days on standby. The mouse sleeps after 5 minutes of inactivity to save power and can be woken with any click.
- 【Colorful LED Breathing Light】: Features 7 colorful LED lights that change randomly, adding a fun atmosphere to your workspace.
- 【Portable Mouse】Compact size (4.4 x 2.3 x 1.1 inches) makes it easy to fit in your laptop bag. Lightweight and ergonomic, it's perfect for travel. Contact us anytime for support.
- 【Wide Compatibility】: Works with laptops, PCs, tablets, and smartphones across various operating systems, including Android, Windows, and Mac. Ideal for home, office, and travel.
Choose the right capture scope
| Need | Suitable approach | Important boundary |
|---|---|---|
| Let the user choose a window, tab, or display and save a still | getDisplayMedia(), followed by frame extraction and image encoding |
The user chooses the surface in the browser picker; a display-surface preference cannot force a particular source. |
| Capture a particular DOM element | Consider Element Capture or Region Capture where supported | These are additional APIs with their own compatibility requirements; they still build on display capture. |
| Capture a page or URL without opening a user-facing picker | Use a server-side browser screenshot service or browser automation designed for that workflow | This is a different task from client-side screen sharing and does not capture a user’s arbitrary desktop window. |
The displaySurface: "window" setting in the example expresses a preference for window capture; it does not remove other choices from the browser’s picker. Options are applied after source selection. For current option behavior, browser-specific support, and error conditions, consult MDN’s getDisplayMedia() reference.
Security, privacy, and embedding requirements
- Explain the action clearly. A selected surface may show private information. Tell users what can be captured before opening the picker, and avoid sending captured pixels to a server unless the user understands and agrees to that separate action.
- Respect browser indicators. Browser prompts and capture indicators are part of the user’s safety model; do not suggest that capture is invisible or automatic.
- Check embedding policy. If the page is inside an iframe and Permissions Policy is used, the
display-capturedirective must allow the relevant document to use screen capture. See MDN’s Screen Capture API guide. - Verify environment support. MDN marks
getDisplayMedia()as having limited availability. Support forImageCapture.grabFrame()and Element/Region Capture is separate. Test the browser and operating-system combinations your application actually supports.
Troubleshooting common failures
| Symptom | Likely cause | What to do |
|---|---|---|
navigator.mediaDevices or getDisplayMedia is missing |
The browser, context, or embedding environment does not expose the API. | Use a supported secure context, check the target browser’s current compatibility, and inspect iframe Permissions Policy settings. |
| The request rejects when called | The call was not made during transient user activation, permission was denied, the document is inactive, or capture is unavailable. | Invoke it directly in the click handler, keep the document active, and present a useful cancellation or failure message. |
| The user closes the picker | Picker cancellation is a normal user choice, not a successful capture. | Catch the rejection, restore the button, and let the user try again without implying a file was created. |
ImageCapture is undefined or grabFrame() fails |
The browser lacks that interface or the track ended before the frame was read. | Feature-detect ImageCapture, verify the video track is live, and test against the supported browser matrix. Consider a video-element-and-canvas fallback only after validating it in the browsers you support. |
The PNG is empty or toBlob() returns null |
The canvas was not drawn, has invalid dimensions, lacks a 2D context, or image encoding failed. | Check the bitmap dimensions, confirm drawImage() completed, and handle a null Blob before creating a download URL. |
| The download does not appear | Browser download behavior or user settings blocked the programmatic download, or the generated link was not usable. | Keep the visible download link in the page as a fallback and leave its object URL alive until the user has had a chance to use it. |
Performance and reliability considerations
For a single still, capture one frame and stop the stream immediately rather than leaving a screen-sharing session active. The bitmap and canvas use memory proportional to the captured pixel dimensions; very large displays can require substantial memory. Avoid retaining multiple full-size bitmaps or object URLs, and release each when no longer needed.
Rank #4
- Your hand can relax in comfort hour after hour with this ergonomically designed mouse. Its contoured shape with soft rubber grips, gently curved sides and broad palm area give you the support you need for effortless control all day long.
- You’ve got the control to do more, faster. Flipping through photo albums and Web pages is a breeze, especially for right-handers—with three standard buttons plus Back/Forward buttons that you can also program to switch applications, go full screen and more. And side-to-side scrolling plus zoom gives you the power to scroll horizontally and vertically through your music library, maps and Facebook feeds, and zoom in and out of photos and budget spreadsheets with a click.* * Requires Logitech SetPoint software (Windows) or Logitech Control Center software (Mac OS X)
- Two years of battery life practically eliminates the need to replace batteries. ** The On/Off switch helps conserve power, smart sleep mode extends battery life and an indicator light eliminates surprises. ** Battery life may vary based on user and computing conditions.
- The tiny Logitech Unifying receiver stays in your laptop. There’s no need to unplug it when you move around, so there’s less worry of it being lost. And you can easily add compatible wireless mice and keyboards to the same wireless receiver.
Do not assume the requested surface size or frame arrives instantly, or that every browser uses the same picker choices. Handle a missing track, an ended track, a null Blob, user cancellation, and encoding failure as ordinary branches. If you need repeatable captures of URLs for a backend workflow, the user-facing screen picker is not the right mechanism.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If the goal is to capture a website URL rather than ask a visitor to share their screen, ScreenshotNeo provides a screenshot API and MCP server. A single GET request returns an image or PDF; its clean-shot flow accepts cookie consent and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture, and each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, with the response identifying the page verdict and billing status. Its MCP server offers screenshot tools to Claude, Cursor, and other MCP clients.
Best Value
- 【Plug and Play for Home/Office/School】The wireless computer mouse features 2.4GHz connectivity, delivering a stable, interference-free connection up to 32ft. Designed for 𝐦𝐞𝐝𝐢𝐮𝐦 𝐭𝐨 𝐥𝐚𝐫𝐠𝐞 𝐬𝐢𝐳𝐞𝐝 𝐡𝐚𝐧𝐝𝐬, it ensures comfortable use all day. Simply plug in the USB-A receiver for instant pairing—no drivers needed. 📌📌 If the mouse isn’t suitable, place the USB receiver in the battery compartment and return both.
- 【3 Levels Adjustable DPI】This travel USB mouse offers 3 adjustable DPI settings (800, 1200, 1600), allowing you to customize sensitivity for precise design work. Effortlessly switch to match your task and elevate your productivity. 📌 Please remove the film at the bottom of the mouse before use.
- 【Effortless Browsing】Equipped with forward and backward buttons, this computer mice streamlines your workflow, making it easy to navigate through web pages and files with a simple click. 📌Side button does not work on Mac.
- 【Visible Indicator Light】 The pc mouse features a visual indicator for DPI levels and low battery alerts. The red light flashes once for 800 DPI, twice for 1200 DPI, and three times for 1600 DPI. When the battery level is below 10%, the light flashes red until the mouse is completely out of power.
- 【Click to Wake】With smart sleep mode, it saves power by standby after 10 inactive minutes, just 2-3 clicks to wake. This efficient design delivers 3x longer battery life than motion-wake mice. Engineered for durability, its buttons and scroll wheel are tested for 10 million clicks, ensuring long-term reliability and consistent performance.
cURL example (see the ScreenshotNeo API documentation for options):
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo includes 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000. This captures a URL through the service, not the user’s browser window. Sign up for the free plan.
Frequently Asked Questions
Can a website capture a browser window without asking the user?
No. The browser’s screen-capture picker and permission prompt are required for each getDisplayMedia() request.
Does getDisplayMedia() return a PNG?
No. It returns a MediaStream; the example extracts one frame and encodes it as a PNG Blob.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteWill displaySurface: "window" force a window to be selected?
No. It is a preference for the resulting stream and cannot silently choose a source or remove picker options.
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.

