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

To capture a scrollable modal’s complete contents, render the element that actually scrolls and set html2canvas’s rendering window to that element’s scrollWidth and scrollHeight. In a typical dialog, that is the inner content panel, not the outer dialog shell:

const target = document.querySelector('.modal-body');

const canvas = await html2canvas(target, {
  windowWidth: target.scrollWidth,
  windowHeight: target.scrollHeight,
});

If the result is still cut off, verify the scrolling element, distinguish window dimensions from canvas dimensions and scroll offsets, then check browser canvas limits, CSS support and cross-origin images.

Why a modal capture gets cut off

A modal often has several nested boxes: an overlay, dialog shell, header, body and footer. CSS commonly gives only the body overflow: auto and a constrained height. The browser viewport shows a slice of that body, so a normal html2canvas call reproduces the visible slice rather than the body’s complete scrollable extent.

html2canvas does not take a native screenshot of the already-composited tab. It reads the DOM and styles, then paints an image onto a canvas. The element you pass is therefore crucial: selecting the shell when the body owns the scrollbar can leave the content clipped or produce dimensions that do not describe the intended output.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Snagit 2024 - Screen Capture & Image Editor [PC/Mac Online Code]
  • Easily record quick videos of your screen and camera that offer the same connection as a meeting without the calendar wrangling
  • Draw on your screen as you record video with customizable arrows, squares, and step numbers to emphasize important information
  • Provide clear feedback and explain complex concepts with easy-to-use professional mark-up tools and templates
  • Instantly create a shareable link where your viewers can leave comments and annotations or upload directly to the apps you use every day
  • Version Note: This listing is for Snagit 2024. Please note that official technical support and software updates for this version are scheduled to conclude on December 31, 2026.

Identify the element that owns the scrollbar

Inspect the DOM, not the component name

Use browser developer tools and find the element whose scrollbar moves when you scroll the modal content. Check its scrollHeight and scrollWidth against clientHeight and clientWidth. A scrolling element normally has a larger scroll dimension than its client dimension.

const candidates = document.querySelectorAll('.modal, .modal *');
for (const el of candidates) {
  if (el.scrollHeight > el.clientHeight || el.scrollWidth > el.clientWidth) {
    console.log(el, {
      scrollWidth: el.scrollWidth,
      scrollHeight: el.scrollHeight,
      clientWidth: el.clientWidth,
      clientHeight: el.clientHeight,
    });
  }
}

Class names such as .modal-body are only examples. Frameworks may use a differently named content pane, or the dialog itself may own the scrolling. Choose the smallest element that contains everything you need.

Decide whether chrome belongs in the image

If the screenshot should contain only the long content, capture the scrolling panel. If it must include a header, footer, backdrop or close button, capture an enclosing element and confirm that its scroll dimensions cover the complete composition. There is no universal selector that works for every modal layout.

The documented full-content fix

Basic capture

const target = document.querySelector('.modal-body');
if (!target) throw new Error('Scrollable modal content was not found');

const canvas = await html2canvas(target, {
  windowWidth: target.scrollWidth,
  windowHeight: target.scrollHeight,
});

document.body.appendChild(canvas);

windowWidth and windowHeight define the virtual rendering window html2canvas uses while cloning and painting the page. Setting them to the target’s scroll dimensions lets the cloned render account for content that is outside the visible viewport.

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

Save the result as an image

const target = document.querySelector('.modal-body');
if (!target) throw new Error('Scrollable modal content was not found');

const canvas = await html2canvas(target, {
  windowWidth: target.scrollWidth,
  windowHeight: target.scrollHeight,
});

const link = document.createElement('a');
link.download = 'modal.png';
link.href = canvas.toDataURL('image/png');
link.click();

For JPEG output, use canvas.toDataURL('image/jpeg', 0.9). PNG preserves text and transparency better; JPEG is usually smaller for photographic content.

Rank #2
Screen recorder software for PC – record videos and take screenshots from your computer screen – compatible with Windows 11, 10, 8, 7
  • Record videos and take screenshots of your computer screen including sound
  • Highlight the movement of your mouse
  • Record your webcam and insert it into your screen video
  • Edit your recording easily
  • Perfect for video tutorials, gaming videos, online classes and more

Include remote images when permitted

const target = document.querySelector('.modal-body');
if (!target) throw new Error('Scrollable modal content was not found');

const canvas = await html2canvas(target, {
  windowWidth: target.scrollWidth,
  windowHeight: target.scrollHeight,
  useCORS: true,
});

useCORS: true asks the browser to load cross-origin images with CORS. It succeeds only when each image server sends a suitable Access-Control-Allow-Origin header. The option cannot bypass the browser’s origin policy. If the server cannot provide permission, use a configured proxy or remove the image from the capture.

Dimensions, scroll positions and ignored elements

Do not confuse the size options

  • windowWidth and windowHeight: the virtual window used during rendering. They can change responsive breakpoints and are the primary fix for content outside the visible viewport.
  • width and height: the canvas dimensions. They control the output bitmap and are not interchangeable with the window dimensions.
  • scrollX and scrollY: the scroll position used for rendering. They matter for fixed-position elements and for captures that intentionally start at an offset.

For a full modal body, start with the scroll-dimension window settings and leave offsets at their defaults. Add an explicit offset only when your layout or fixed controls require it.

Hide controls that should not appear

Add data-html2canvas-ignore to buttons, resize grips or other interface elements that should be excluded:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<button data-html2canvas-ignore>Close</button>

The element remains visible in the live modal but is omitted from the rendered image.

Wait until the modal is complete

Measure dimensions after the dialog is open, fonts have loaded and asynchronous content has been inserted. Measuring a collapsed or still-loading panel gives html2canvas the wrong extent. A simple application-level sequence is:

Rank #3
Debut Screen and Video Recorder Free [PC Download]
  • Screen capture software records all your screens, a desktop, a single program or any selected portion
  • Capture video from a webcam, network IP camera or video input device
  • Use video overlay to record your screen and webcamsimultaneously
  • Intuitive user interface to allow you to get right to video recording
  • Save your recordings to ASF, AVI, and WMV
  1. Open the modal.
  2. Insert or fetch its content.
  3. Wait for the layout to settle (for example, after the relevant render callback).
  4. Read scrollWidth and scrollHeight.
  5. Call html2canvas with those values.

A robust reusable helper

async function captureScrollableModal(selector) {
  const target = document.querySelector(selector);
  if (!target) {
    throw new Error(`Scrollable modal element not found: ${selector}`);
  }

  // Force layout before reading dimensions.
  const width = target.scrollWidth;
  const height = target.scrollHeight;
  if (!width || !height) {
    throw new Error('The target has no measurable scrollable area');
  }

  const canvas = await html2canvas(target, {
    windowWidth: width,
    windowHeight: height,
    useCORS: true,
  });

  if (canvas.width !== width || canvas.height !== height) {
    console.warn('Canvas dimensions differ from target dimensions', {
      target: { width, height },
      canvas: { width: canvas.width, height: canvas.height },
    });
  }

  return canvas;
}

captureScrollableModal('.modal-body').then(canvas => {
  const link = document.createElement('a');
  link.download = 'modal.png';
  link.href = canvas.toDataURL();
  link.click();
});

The dimension comparison is diagnostic rather than a guarantee: device-pixel settings, browser behavior and implementation details can affect the final bitmap.

When the dimension fix still fails

The target is still the wrong element

If the canvas height matches a short shell while the body remains clipped, the body owns scrolling and must be captured directly. Conversely, capturing only the body omits a header or footer that sits outside it. Recheck which scrollbar moves and compare the target’s measured dimensions with the intended image.

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

The canvas is blank or only partly rendered

Very large canvases can exceed browser or platform limits. Limits vary by browser and device, so no single maximum is a safe universal rule. Split exceptionally long content into smaller captures, reduce the rendered area, or use a native capture mechanism appropriate to your application.

Styles do not match the modal

html2canvas implements CSS properties individually and its CSS support is incomplete. Correct dimensions do not guarantee identical effects for every filter, blend mode, transform, pseudo-element or advanced layout feature. Isolate the affected style, check the project’s current support, and simplify or replace unsupported styling when exact visual fidelity matters.

Images taint the canvas or disappear

For remote images, use useCORS: true only when the image host grants permission. Otherwise configure a proxy, serve the assets from the same origin, or omit them. A browser policy cannot be defeated by a JavaScript flag.

Rank #4
Debut Video Capture Software to Record from a Webcam, Computer Screen or Device [Download]
  • Capture video directly to your hard drive
  • Record video in many video file formats including avi, wmv, flv, mpg, 3gp, mp4, mov and more
  • Capture video from a webcam, network IP camera or a video input device (e.g.: VHS recorder)
  • Screen capture software records the entire screen, a single window or any selected portion
  • Digital zoom with the mouse scroll wheel, and drag to scroll the recording window

Fixed elements appear in an unexpected place

Fixed-position elements are rendered relative to the configured window and scroll position. Adjust scrollX or scrollY deliberately, and decide whether those controls should instead carry data-html2canvas-ignore.

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

Performance and reliability considerations

Keep the capture area intentional

A full scroll height increases the number of pixels html2canvas must paint and encode. Capture the content panel rather than the entire page, hide irrelevant widgets, and avoid repeatedly capturing while the user is scrolling. Trigger a capture after content stabilizes.

Plan for long documents

For a modal that can grow to many screenfuls, test representative content on the browsers and devices you support. If a single bitmap approaches practical canvas limits, capture sections and stitch them in an image workflow, or use a browser-native screenshot facility when your environment provides one.

Understand what “screenshot” means here

html2canvas is a DOM reconstruction tool. It is useful when you need an element image inside a web application, but it is not equivalent to a browser tab screenshot. Browser extensions that need an actual tab image should use the browser’s native tab screenshot API, as recommended by the html2canvas FAQ.

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

Or skip the browser setup

If you need a server-side image of a URL rather than an in-page DOM canvas, ScreenshotNeo provides a website screenshot API and MCP server. It accepts the consent banner like a visitor, removes more than 60 known consent platforms, newsletter popups and chat widgets before capture, and bills only clean shots. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed; the response identifies the result with X-Page-Verdict and X-Billed headers. It can also capture full pages and selected CSS elements, with custom CSS or JavaScript, waits, device and viewport settings, cookies, headers and other controls.

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

One GET request returns PNG, JPEG, WebP or PDF. See the ScreenshotNeo documentation for parameter details.

Best Value
Capture Card, 4K HDMI Video Capture Card, Game Capture Card, 1080P 60FPS Video Capture Device, HDMI to USB 3.0 Capture Card for Streaming, Work with Camera/Xbox/PS4/PS5/PC/OBS
  • 【1080P HD High Quality】Capture resolution up to 1080p for video source and it is ideal for all HDMI devices such as PS4, PS3, Xbox One, Xbox 360, Wii U, DVDs, DSLR, Camera, Security Camera and set top box. Note: Video input supports 4K30/60Hz and 1080p120/144Hz. Does not support 4K120Hz/144Hz. Output supports up to 2K30Hz.
  • 【Plug and Play】No driver or external power supply required, true PnP. Once plugged in, the device is identified automatically as a webcam. Detect input and adjust output automatically. Won't occupy CPU, optional audio capture. No freeze with correct setting.
  • 【Compatible with Multiple Systems】suitable for Windows and Mac OS. High speed USB 3.0 technology and superior low latency technology makes it easier for you to transmit live streaming to Twitch, Youtube, Facebook, Twitter, OBS, Potplayer and VLC.
  • 【HDMI LOOP-OUT】Based on the high-speed USB 3.0 technology, it can capture one single channel HD HDMI video signal. There is no delay when you are playing game live.
  • 【Support Mic-in for Commentary】Rybozen capture card has microphone input and you can use it to add external commentary when playing a game. Please note: it only accepts 3.5mm TRS standard microphone headset.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
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)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo includes an MCP server for Claude, Cursor and other MCP clients, so AI agents can call take_screenshot, get_page_info and capture_pdf. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.

FAQ

Should I set the modal’s CSS height to its full scroll height?

Not necessarily. The documented approach changes html2canvas’s rendering window; altering live layout can affect responsive styling and the user experience. First select the correct scrolling element and pass its measured dimensions.

Can html2canvas capture content that is display:none?

Hidden content has no rendered layout to measure or paint. Make the modal and its content renderable, wait for layout, then capture it.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Why does a native tab screenshot differ from html2canvas?

A native screenshot captures the browser’s composited pixels. html2canvas rebuilds the image from DOM nodes and supported CSS, so unsupported properties, cross-origin images and browser limits can produce differences.

Frequently Asked Questions

Does html2canvas automatically scroll through a modal?

No. It renders the target using its configured window. Set that window from the target’s scroll dimensions and ensure the target owns the scrolling.

What is the best output format for modal text?

PNG is usually the safest choice for text, UI edges and transparency. Use JPEG when smaller photographic output matters more than lossless text edges.

Can I capture only one component inside the modal?

Yes. Pass that component to html2canvas, provided its dimensions include all content you intend to render.

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.

Quick Recap

Bestseller No. 2
Screen recorder software for PC – record videos and take screenshots from your computer screen – compatible with Windows 11, 10, 8, 7
Screen recorder software for PC – record videos and take screenshots from your computer screen – compatible with Windows 11, 10, 8, 7
Record videos and take screenshots of your computer screen including sound; Highlight the movement of your mouse
$19.99
Bestseller No. 3
Debut Screen and Video Recorder Free [PC Download]
Debut Screen and Video Recorder Free [PC Download]
Capture video from a webcam, network IP camera or video input device; Use video overlay to record your screen and webcamsimultaneously
Bestseller No. 4
Debut Video Capture Software to Record from a Webcam, Computer Screen or Device [Download]
Debut Video Capture Software to Record from a Webcam, Computer Screen or Device [Download]
Capture video directly to your hard drive; Screen capture software records the entire screen, a single window or any selected portion
$39.99

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.