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

“Unable to load image undefined” is a symptom, not a single html2canvas diagnosis. Start by finding the image or CSS background URL that the captured element references. Confirm that the value is present and valid, then inspect that request in your browser’s Network panel. If the image is on another origin, address CORS or use a properly configured proxy; increasing a timeout helps only when a valid image is merely slow.

This guide walks through a repeatable diagnosis, working html2canvas code, cross-origin choices, isolation techniques, and production troubleshooting. It also shows a browser-free alternative when you only need a reliable website image or PDF.

What the message actually tells you

The wording usually appears while html2canvas is cloning a DOM subtree and trying to load an image used by that subtree. The failing resource might be an <img>, a CSS background-image, a pseudo-element, or an image URL assembled by JavaScript. The particular report that popularized this wording does not identify where its undefined value came from, so the message alone cannot prove one universal root cause.

html2canvas reconstructs a representation from DOM and style information; it is not a native screenshot of the browser’s compositor. Browser content policies still apply. As the project puts it, “html2canvas does not get around content policy restrictions set by your browser.”

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.
#1 Best Overall
Sale
Kodak PIXPRO FZ45 Digital Camera, 16MP Point & Shoot (Black)
  • 16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting
  • Optical Zoom: 4x optical zoom with a 27mm wide angle lens for flexible framing indoors or outdoors
  • Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
  • Memory Support: Works with Class 10 SD, SDHC, or SDXC cards up to 512GB
  • LCD Screen and Battery: 2.7in LCD screen with 2 AA alkaline batteries for convenient on-the-go use

Fix it in the order most likely to work

  1. Locate every image reference. Inspect the captured element and its descendants in DevTools. Check each img.src, srcset, inline style, stylesheet rule, and generated content. Look specifically for an absent attribute, an empty string, or the literal string undefined.
  2. Test the URL normally. Paste an absolute URL into a new tab where possible. In DevTools, reload the page with the Network panel open and inspect the image request’s status, redirects, response headers, authentication, and timing. A 404, 403, redirect to a login page, certificate failure, or timeout must be fixed at the source.
  3. Check the image origin. A different scheme, host, or port is cross-origin. With the documented defaults (allowTaint: false, useCORS: false, proxy: null), html2canvas will not draw an image that would taint the canvas.
  4. Choose a cross-origin route. If the image server is under your control, have it return the appropriate CORS response and request it with useCORS: true. If it cannot provide CORS, fetch the image through a proxy that your application operates and configure that proxy in html2canvas. A random proxy URL does not bypass browser security.
  5. Adjust timeout only for a slow, valid resource. The documented imageTimeout default is 15,000 milliseconds. A larger value can help an image that eventually succeeds; it cannot repair an undefined URL, a denied request, or a 404. Setting imageTimeout: 0 disables the timeout, so use that cautiously and verify the behavior of the version installed in your project.
  6. Isolate the subtree. Temporarily remove suspicious images, or exclude them with data-html2canvas-ignore or the ignoreElements callback. If the render then succeeds, restore images in groups until the offending reference is identified.

A minimal, diagnosable html2canvas setup

Install the package and capture an element through its Promise-based API:

npm install html2canvas
import html2canvas from 'html2canvas';

const target = document.querySelector('#invoice');
if (!target) throw new Error('Capture target not found');

html2canvas(target, {
  useCORS: true,
  imageTimeout: 15000,
  logging: true
}).then(canvas => {
  document.body.appendChild(canvas);
}).catch(error => {
  console.error('html2canvas failed', error);
});

Use useCORS only when the image host sends a permissive CORS response. Keep logging enabled while diagnosing so the console identifies the stage at which loading fails. Validate the target before calling html2canvas; an unrelated null target can obscure the image problem.

Find undefined values before capture

function inspectImages(root) {
  for (const img of root.querySelectorAll('img')) {
    console.log({ element: img, src: img.getAttribute('src'), resolved: img.src });
  }
  for (const el of root.querySelectorAll('*')) {
    const bg = getComputedStyle(el).backgroundImage;
    if (bg && bg !== 'none') console.log('background', el, bg);
  }
}

const target = document.querySelector('#invoice');
inspectImages(target);
await html2canvas(target, { useCORS: true });

An empty src attribute can resolve relative to the current document, while a JavaScript template such as url(${imageUrl}) can become the literal text undefined. Log the original attribute and the resolved property so you can distinguish those cases.

Rank #2
Sale
Kodak PIXPRO FZ55-BK 16MP CMOS Sensor Camera 5X Optical Zoom 28mm Wide
  • 16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting
  • Optical Zoom: 5x optical zoom with a 28mm wide angle lens for flexible framing indoors or outdoors
  • Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
  • Memory Support: Works with Class 10 SD, SDHC, or SDXC cards up to 512GB
  • LCD Screen and Battery: 2.7in LCD screen and a rechargeable lithium-ion battery for on-the-go use

Cross-origin images: CORS or proxy

Use CORS when you control the image host

Configure the image server to return an Access-Control-Allow-Origin value that includes the page origin (or an intentionally broader value appropriate for your security model). Then request with useCORS: true. The response must be CORS-readable; adding the option cannot manufacture missing response headers.

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

Use a proxy when the host cannot grant CORS

A proxy on your server can retrieve the image and serve it from an origin your page is allowed to read. The proxy must validate destinations, restrict protocols and hosts, handle redirects safely, set an image content type, and avoid leaking private cookies or authorization headers. Point html2canvas’s proxy option at that implementation. Do not place credentials in a public client-side proxy URL.

Understand allowTaint

Setting allowTaint: true does not make a cross-origin image readable or remove browser policy. It permits drawing content that may taint the canvas, after which operations such as exporting pixel data can fail. Prefer a valid CORS response or a controlled proxy when you need canvas.toDataURL() or toBlob().

Rank #3
Sale
Digital Camera, Latest FHD 1080P Digital Camera for Teens with SD Card Anti Shake Point and Shoot Cameras Portable 16X Zoom Compact Small Cameras for Kids Boys Girls Seniors with Wrist Strap
  • Latest Digital Camera Built-in Fill Light : This compact digital camera is paired with a powerful CMOS processor and image stabilization to help you take & record the most exciting moments in 44 MP quality images & FHD 1080P quality videos anywhere, anytime. Plus, there is also a built-in fill light to help you take high quality pictures even in low light&dark settings, making this the perfect camera for all indoors/outdoors situations.
  • Long-Lasting Battery Life & 16X Digital Zoom :This point and shoot camera will retain its battery charge even after long use. The controls and functions are easy to operate making this the perfect choice for children, teens and younger. This kids camera supports 16x digital zoom, you can zoom in or out the subject by pressing the W/T button for taking still photos to zoom in or out on distant objects and capture all the details you need.
  • Multifunctional & Portable Digital Camera: This cheap digital camera is slim enough to fit in your pocket. You'll easily be able to take it with you on all your indoor/outdoor activities and adventures and ideal for beginners, children and teenagers. This kids digital camera is equipped with 20 filters, anti-shaking, self-timer, continuous shooting, date stamp, time-lapse recording, smile capture, internal MIC and speaker (recording sound videos), great for your daily photography needs.
  • WEBCAM & PAUSE FUNCTION : More than just a FHD 1080p digital camera, it also works as a webcam for video calls and vlogging. Connect the camera to the computer, press shutter and power button at the same time and the camera will automatically turn on webcam mode for all your video calling and live streaming needs. The pause function allows you to pause when seeing playback videos.
  • A Must Have Photography Device : This digital camera with SD card made from high-quality materials, this retro camera is safe and durable. Perfect for all ages to develop & improve their photographic abilities and observation skills. Our dedicated and experienced 24/7 support team is available for all after purchase troubleshooting, questions and technical help.

When timeout, caching, or page timing is the real issue

Wait until images are complete before starting the capture, especially after inserting a component or changing its URL:

async function waitForImages(root) {
  const images = [...root.querySelectorAll('img')];
  await Promise.all(images.map(img => {
    if (img.complete) return img.decode?.().catch(() => {});
    return new Promise(resolve => {
      img.addEventListener('load', resolve, { once: true });
      img.addEventListener('error', resolve, { once: true });
    });
  }));
}

const target = document.querySelector('#invoice');
await waitForImages(target);
const canvas = await html2canvas(target, { imageTimeout: 30000, useCORS: true });

This waits for browser load events; it does not fix a failed request. If an image endpoint responds slowly, improve that endpoint or raise the timeout moderately. If it never responds, a longer timeout only delays failure. Confirm the installed html2canvas release before relying on option defaults, because documentation pages may lag current releases.

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

Exclude a bad element while you investigate

Mark an element in markup:

<img src="https://third-party.example/avatar.png" data-html2canvas-ignore alt="">

Or filter it in code:

const canvas = await html2canvas(document.querySelector('#invoice'), {
  ignoreElements: element => element.matches('.live-chat, .remote-avatar')
});

If excluding the element makes the capture succeed, add its URL to your network checks and then restore it after fixing the source or origin policy. This is a diagnostic branch, not a permanent way to hide required content.

Rank #4
Kodak PIXPRO FZ55-RD 16MP Camera 5X Optical Zoom 28mm Wide Angle 1080p
  • 16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting
  • Optical Zoom: 5x optical zoom with a 28mm wide angle lens for flexible framing indoors or outdoors
  • Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
  • Memory Support: Works with Class 10 SD, SDHC, or SDXC cards up to 512GB
  • LCD Screen and Battery: 2.7in LCD screen and a rechargeable lithium-ion battery for on-the-go use
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failures and precise fixes

Symptom Likely cause Fix
Console prints “undefined” immediately Missing data property, empty attribute, or bad template interpolation Log the source value before rendering; provide a real absolute or resolvable URL, or omit the image.
Network request is 404 Stale path, wrong base URL, or deployment asset mismatch Correct the generated path and verify the deployed asset exists.
Request is 401/403 Image requires credentials or hotlink permission Serve an authorized image through your backend or configure an appropriate CORS/auth flow; do not expose secrets in the browser.
Request succeeds but canvas export throws a security error Cross-origin response tainted the canvas Use server CORS plus useCORS: true, or a controlled proxy. allowTaint is not a security bypass.
Only remote images fail Origin policy or absent CORS headers Compare origins and response headers; choose CORS or proxy.
Large images fail after about 15 seconds The documented default timeout elapsed Fix upstream latency or increase imageTimeout for a valid, eventually successful URL.
Capture works after removing one widget Widget injects a broken image or cross-origin resource Exclude it, replace its asset, or load it through a policy-compliant route.

Production checklist

  • Record the html2canvas version, browser, operating system, options, captured selector, and exact failing URL.
  • Test both a same-origin image and the problematic image to separate library setup from resource policy.
  • Check redirects and final response headers, not only the initial URL.
  • Do not treat a timeout increase as a fix for malformed data.
  • Keep proxy fetching server-side, validate destinations, and strip credentials unless explicitly required.
  • Decide whether a failed image should block the whole capture or be excluded with an explicit marker.

Or skip the browser setup

If your goal is a screenshot or PDF of a public URL rather than a DOM-canvas experiment, ScreenshotNeo makes one request and returns PNG, JPEG, WebP, or PDF. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status.

cURL (see the ScreenshotNeo API docs):

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(`${res.status} ${res.statusText}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

ScreenshotNeo also provides an MCP server with take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. Every feature is on every plan: 1,000 shots per month are free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.

Frequently Asked Questions

Can I solve the message by setting allowTaint: true?

No. That option can permit a tainted canvas, but it does not grant cross-origin read access and may prevent exporting pixel data. Use CORS or a controlled proxy when export is required.

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

Why does the page look correct in the browser but fail in html2canvas?

A browser can display an image without allowing script access to its pixels. html2canvas needs a policy-compliant, readable image to draw and export it.

Should I set imageTimeout to zero permanently?

Usually not. Zero disables the timeout and can leave captures waiting indefinitely when an endpoint is unavailable. Use it only with deliberate monitoring and an outer job timeout.

Quick Recap

SaleBestseller No. 1
Kodak PIXPRO FZ45 Digital Camera, 16MP Point & Shoot (Black)
Kodak PIXPRO FZ45 Digital Camera, 16MP Point & Shoot (Black)
16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting; Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
$99.99
SaleBestseller No. 2
Kodak PIXPRO FZ55-BK 16MP CMOS Sensor Camera 5X Optical Zoom 28mm Wide
Kodak PIXPRO FZ55-BK 16MP CMOS Sensor Camera 5X Optical Zoom 28mm Wide
16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting; Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
$139.99
Bestseller No. 4
Kodak PIXPRO FZ55-RD 16MP Camera 5X Optical Zoom 28mm Wide Angle 1080p
Kodak PIXPRO FZ55-RD 16MP Camera 5X Optical Zoom 28mm Wide Angle 1080p
16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting; Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
$139.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.