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

First decide what “screenshot” means for your feature: a reconstructed image of content your page controls, a capture of a tab or screen the user selects, or an automated image of a URL generated on a server. These are different jobs. Use DOM reconstruction for an app-controlled element, getDisplayMedia() when the user must choose what to share, and server-side browser automation or a screenshot API to capture remote pages.

Choose the kind of screenshot you need

Need Starting point Main trade-off
Capture an element or region your app controls in the current page A DOM reconstruction library such as html2canvas It rebuilds an image from DOM information rather than copying the browser’s rendered pixels. Unsupported CSS and cross-origin content can be missing or look different.
Let a user choose a tab, window, or screen and capture what is displayed navigator.mediaDevices.getDisplayMedia() The user must choose a surface and grant access. Browser support and policy restrictions vary.
Capture remote URLs or automate repeatable captures outside a user’s browser Server-side browser automation such as Puppeteer or Playwright, or a screenshot API You need a server-side capture setup or a service; html2canvas itself is client-side only.

Choose based on capture scope, required fidelity, target browsers, cross-origin content, and whether the capture happens in the client or on a server. The approaches are not interchangeable. The html2canvas documentation describes its DOM-based reconstruction and limitations; its FAQ points to Puppeteer and Playwright for server-side browser work.

Render an app-controlled element with html2canvas

Use this when your page owns the content and you want to let a visitor save a screenshot-like image of a particular region. html2canvas traverses DOM information and draws a reconstruction; it does not take a literal screenshot of the browser’s pixels. Treat the result as a rendered approximation, not a guaranteed pixel-perfect copy.

Install and add a capture button

Install the package in your project with npm install html2canvas. The following example assumes a JavaScript module-based app and an element with the ID report:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Nicpro Carpenter Pencils with Sharpener, Mechanical Pencil for Construction
  • Valued Carpenter Pencil Set: You will get 2 pcs solid carpenter pencils with 26 piece 2.8 mm refills, 1 replaceable sharpener, 1 plastic storage box.The complete carpenter pencils combination allows you to finish your work faster and more easily
  • Deep Hole Marker Pencil: The deep-hole construction pencils adopts 45mm elongated tip design, which is more convenient to mark in the small hole or in other tight areas that other carpenter markers cannot reach
  • Carpenter Pencils with Sharpener: The sharpener is screwed into the top of the work pencil, which won't get lost either. Built-in pencil sharpener that keep the lead with pointed and smooth to Improves line of sight in fine work
  • Stronger Solid Lead: This work pencil is matched with a 2.8 mm thick lead , which is much thicker and stronger during the drawing process of construction work, it will not break or damage easily
  • Marks on Various Surfaces: 3 colors solid construction pencil can marks on various surfaces,such as metal, plastic, wood, paper etc. Ideals for woodworkers, contractors, craftsmen, builders, merchants and masons
import html2canvas from 'html2canvas';

const button = document.querySelector('#save-screenshot');
const report = document.querySelector('#report');

button.addEventListener('click', async () => {
  if (!report) {
    console.error('The element #report was not found.');
    return;
  }

  button.disabled = true;
  try {
    const canvas = await html2canvas(report, {
      backgroundColor: '#ffffff',
      scale: window.devicePixelRatio || 1
    });

    const link = document.createElement('a');
    link.download = 'report.png';
    link.href = canvas.toDataURL('image/png');
    link.click();
  } catch (error) {
    console.error('Could not render the element:', error);
    alert('The screenshot could not be created. Check the page content and image permissions, then try again.');
  } finally {
    button.disabled = false;
  }
});

Provide the corresponding controls in your page:

<button id="save-screenshot" type="button">Save report image</button>
<section id="report">
  <h1>Monthly report</h1>
  <p>Content controlled by your application goes here.</p>
</section>

The scale option uses the device pixel ratio when available, which can create a larger output image on high-density displays. If the output is too large or slow, set a lower fixed scale. Avoid very large capture regions: the resulting canvas consumes memory, and browsers impose canvas-size limits. html2canvas’s FAQ discusses canvas dimensions and related failure cases.

What may be absent or different

  • Unsupported CSS or browser-rendered content: the library reconstructs from DOM information, so the output can differ from what the browser painted.
  • External images: an image from another origin needs appropriate CORS permission to be drawn into a canvas. Configure the image host to permit your origin when eligible, or use a same-origin proxy that you control and are authorized to use. A library option cannot override browser security rules.
  • Cross-origin iframes: page JavaScript cannot read another origin’s frame DOM to reconstruct its contents. Do not assume a DOM capture can include protected embedded content.
  • Canvas that is already tainted: browser security restrictions can prevent reading or exporting the result. Correct the source and CORS setup rather than trying to bypass the restriction.

For the underlying constraints and proxy guidance, see the html2canvas documentation and FAQ.

Rank #2
Sale
DEWALT 20V MAX Cordless Drill and Impact Driver, Power Tool Combo Kit , Includes 2 Batteries, Charger and Bag (DCK240C2)
  • Ergonomically Designed: Work in tight areas with a compact design that gets into tough spots
  • Compact and Lightweight: Both tools are designed to fit into difficult to reach spaces. The 1/4" impact driver has a length of 5.55 in. and weighs just 2.8 lbs, while the 1/2" drill/driver measures only 7.5 in. and weighs 3.6 lbs
  • Both the DEWALT impact driver and electric drill driver feature integrated LED work lights with a convenient 20-second delay, ensuring enhanced visibility in dimly lit or challenging work areas
  • One-Handed Loading - Keep one hand free with a 1/4 in. hex chuck that accepts 1 in. bit tips
  • Power drill cordless with 1/2" single sleeve ratcheting chuck provides tight bit gripping strength, making bit changes faster and more secure

Let a user capture a tab, window, or screen

Use the Screen Capture API when the feature really needs the displayed pixels of a surface selected by the user, rather than a reconstruction of your app’s DOM. getDisplayMedia() prompts the user to choose a surface and grant access, then returns a media stream. It cannot silently capture the screen or force a particular source. It requires a secure context in supporting browsers, has limited availability, and can be blocked by Permissions Policy. Check the MDN reference against the browsers you support.

Capture one frame after an explicit click

This example captures a still frame from the selected surface, offers it as a PNG download, and stops the stream tracks promptly after capture:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Push to Unlock,Katerk 6pcs 1/4 inch Hex Shank Aluminum Alloy Screwdriver Bit Holder Light-Weight Quick-Change Extension Bar Keychain Drill Screw Adapter Portable,Black Carabiner,Tool Gifts for Men
  • 【Great Compatibility】This Katerk 1/4 inch hex shank bit holder is specifically designed for 1/4 inch hex shank drill bits. It's compatible with most 1/4 fast hex handles, hex sockets, various electric screwdrivers, and handheld screwdrivers. The bit holder makes it a valuable addition for any handyman.
  • 【Secure and Safe】Built with a secure backup nut design, each drill bit holder securely locks onto your bits, ensuring they stay firmly in place. Additionally, our bit holder incorporates a high-quality steel ball rolling design that holds up to several kilograms of weight, ensuring your various drill bits don't fall off.
  • 【Easy One-Handed Operation】The bit holder for impact driver allows you to change bits single-handedly, simplifying your workflow. Its multi-color design further allows for quick identification of the drill bit you need.
  • 【Compact and Convenient】Thanks to its compact size, this 1/4 inch bit holder is easy to carry around. The bit holder allows for easy attachment to various tools, making this a convenient addition to your construction accessories. The Katerk bit holder is cast from high-quality alloy material, promising a long product lifespan. Despite its rugged strength, the bit holder remains lightweight, making it portable.
  • 【Cool Christmas Gift For Men Stocking Stuffers】 This screwdriver bit holder, driver bit holder, impact bit holder, can be given as a gift to your loved one, especially for anyone involved in construction or electrical work. It's a must-have for stocking stuffers for men and women, tools gifts for dad, tech gadgets for men, gifts for dad, gifts for him, gifts for husband, gifts for boyfriend, cool gadgets for men, and cool gifts for dad.
<button id="capture-screen" type="button">Choose a screen to capture</button>
<script type="module">
const button = document.querySelector('#capture-screen');

button.addEventListener('click', async () => {
  if (!navigator.mediaDevices?.getDisplayMedia) {
    alert('Screen capture is not available in this browser.');
    return;
  }

  button.disabled = true;
  let stream;
  try {
    stream = await navigator.mediaDevices.getDisplayMedia({ video: true });
    const video = document.createElement('video');
    video.srcObject = stream;
    video.muted = true;
    await video.play();

    if (video.videoWidth === 0 || video.videoHeight === 0) {
      throw new Error('The selected surface has no available video frame.');
    }

    const canvas = document.createElement('canvas');
    canvas.width = video.videoWidth;
    canvas.height = video.videoHeight;
    canvas.getContext('2d').drawImage(video, 0, 0);

    const blob = await new Promise(resolve => canvas.toBlob(resolve, 'image/png'));
    if (!blob) throw new Error('The browser could not encode the frame.');

    const url = URL.createObjectURL(blob);
    const link = document.createElement('a');
    link.href = url;
    link.download = 'screen-capture.png';
    link.click();
    setTimeout(() => URL.revokeObjectURL(url), 1000);
  } catch (error) {
    if (error.name === 'NotAllowedError') {
      alert('Capture was cancelled or permission was not granted.');
    } else {
      console.error('Screen capture failed:', error);
      alert('The selected surface could not be captured.');
    }
  } finally {
    stream?.getTracks().forEach(track => track.stop());
    button.disabled = false;
  }
});
</script>

Call the API from a clear user action such as the button above. Explain why the browser picker appears, what the user can select, and how to cancel. Stop the tracks when the still has been captured; if your product instead streams or records for longer, provide an obvious way to end capture and stop tracks then. Browser picker controls are part of the privacy model; Chrome’s screen-sharing guidance explains its capture-surface choices and privacy controls.

Check secure context and policy

Serve the page in a secure context supported by the browser. A site or embedding policy can also disable the feature: MDN documents the display-capture Permissions Policy. If the page is embedded, check the policy and the relevant iframe permissions rather than repeatedly prompting the user. MDN’s Screen Capture API guide describes the stream model and policy configuration.

Rank #4
2 Pack Carpenter Pencils Mechanical Pencils with 12 Refills, (2 Colors)
  • Long Nib and Deep Hole Marker: Our mechanical carpenter pencil with 45mm nib is designed for easy marking of deep holes or narrow areas. These construction pencils are the great choice for woodworking tools, construction tools, carpenter tools, contractor tools, wood carpentry tools and architect tools
  • Extra Refills in 2 Colors for Versatile Marking: The construction mechanical pencil comes with 12 extra 2.8mm refills, including 6 red and 6 black refills. The black refill is suitable for light surfaces, while the red wax is perfect for dark surfaces. Our carpenter mechanical pencil makes sure that you'll have an ample supply for extended use
  • Built-in Sharpener: Our construction pencil comes with a built-in sharpener to ensure the mechanical pencil tip is always sharp and ready for use. Never buy an extra pencil sharpener again. A great tool for any woodworker pencil, contractor pencils. The refill can easily be extended or retracted with a simple click of the pencils mechanical, allowing you to work more efficiently and accurately
  • Portable Clip Design: Our deep hole construction pencil features a portable clip design, easy to carry and attach to your pocket or tool box, so that you can keep the carpenter pencils mechanical close at hand, making it a convenient tool to have on the go. Great gifts choice for carpenters
  • Stronger Pencil Lead: The black refills are made of lead, sturdy and smooth. The red refills are made of wax, clear and light. These marking pencils are much thicker and stronger than normal pencils during the marking process of construction work, suitable for various surfaces, such as glasses, metal, boards, floors, walls, furniture, etc. The written marks can be easily wiped with a wet paper towel when needed
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Generate screenshots on a server

For a remote URL, a scheduled capture, or a repeatable capture that should not depend on a visitor’s browser, render the page in a server-side browser. html2canvas relies on browser globals and is not the server-side screenshot engine; its FAQ suggests investigating Puppeteer or Playwright.

Plan the capture service

A browser-based server capture has different operational needs from a button in a web page. Your service must be able to launch and manage a browser, load the requested URL, wait for the content you need, and return an image or document. Before exposing such a feature, decide which URLs are allowed, how long a capture may run, where output is stored, and how concurrent jobs are limited. Untrusted URL capture can expose a server to requests it should not make; restrict destinations and network access to suit your application. The reviewed documentation does not establish current version requirements, hosting costs, or a tool-by-tool comparison for Puppeteer and Playwright, so choose based on your runtime and validate the deployment environment.

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.
Best Value
Milwaukee 48-22-3104 Inkzall Point Marker, Fine, Black, 4-Pack
  • Milwaukee Ink all Fine Point Marker, Black, 4 Per Pack
  • 4 per pack Features Clog Resistant Marker Tip Writes through Dusty, Wet and Oily Surfaces Durable Marker Tip for Writing on Concrete, OSB and Rough Surfaces
  • Clog resistant tip writes on dusty, wet and oily surfaces and is optimized for rough surfaces such as OSB, cinderblock and concrete
  • Hard hat clip- attaches for easy access
  • Quick dry time with reduced smearing and marking

For a capture that must originate from a server but where you do not want to operate the browser setup, a screenshot API is another route. ScreenshotNeo is a website screenshot API and MCP server for developers. It accepts a URL in one GET request and returns a PNG, JPEG, WebP, or PDF; its options include full-page capture, an element selector, wait conditions, custom headers and cookies, and async jobs. See ScreenshotNeo for the service and its documentation for request parameters.

Or skip the browser setup

For a server-generated screenshot, call the API with a URL and your API key. This cURL example saves a WebP capture:

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

Equivalent Python request:

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)

Equivalent Node.js request:

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 request failed: ${res.status}`);
const bytes = new Uint8Array(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('shot.webp', bytes));

Replace the example URL with the page you are authorized to capture, and keep the API key on the server rather than exposing it in public page JavaScript. ScreenshotNeo removes cookie or consent banners, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers indicating the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Every feature is available on every plan. Read the ScreenshotNeo API documentation for configuration and response details, then sign up free for 1,000 screenshots a month with no card.

Troubleshoot common failures

  • The html2canvas image is missing a remote image: the image host may not grant CORS access, or the image is otherwise unavailable to the canvas. Configure an eligible source for CORS or use a controlled same-origin proxy; DOM code cannot bypass cross-origin rules.
  • An iframe appears blank: if it is cross-origin, your page cannot inspect its DOM to reconstruct it. Capture the content from an authorized source or use a different capture approach.
  • The output differs from the page: html2canvas reconstructs from DOM data, and some CSS or browser content may not reproduce. Test the particular element and browsers that matter; if browser-rendered pixels are required, use user-mediated display capture or server-side browser capture as appropriate.
  • Canvas export fails or the output is empty: check for tainted canvas content, confirm the target element exists, and reduce oversized capture dimensions. Log the caught exception rather than silently returning a broken file.
  • The screen picker does not open: verify that the call follows a direct user action, that the browser supports the API, that the page is in a secure context, and that Permissions Policy does not block display capture.
  • The user dismisses the picker: cancellation is an expected outcome, not an application crash. Handle the rejected promise, leave the page usable, and allow the user to try again.
  • A display capture continues after the still is saved: stop every stream track after capturing the frame. Otherwise the user may see an ongoing capture indicator and the page may retain access longer than necessary.
  • A server capture stalls or consumes too many resources: define time limits, constrain allowed destinations, and control job concurrency and browser lifecycle in your own service. For a managed API, inspect its response status and documented verdict and billing headers.

FAQ

Can JavaScript take a screenshot of the current page without asking the user?

It can reconstruct eligible page content from the DOM with a library, but it cannot silently obtain a native screenshot of the browser or screen. Capturing a display surface requires the user-mediated Screen Capture API flow.

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

Which approach should I use for a page that contains third-party embeds?

Use DOM reconstruction only if the required content is accessible to your page and can be drawn under browser security rules. Cross-origin frames are not readable through your DOM; when their displayed pixels are essential, evaluate user-selected display capture or a server-side capture of an authorized URL.

Can I use html2canvas to take screenshots on the server?

No. Its FAQ identifies it as client-side and points to Puppeteer or Playwright for server-side browser automation.