Console: SecurityError: Failed to execute 'toDataURL' / 'getImageData' on 'HTMLCanvasElement': Tainted canvases may not be exported
You drew an image from another origin onto a canvas without CORS permission, so the browser blocks reading pixels back out.
The canvas has been tainted by cross-origin dataTainted canvases may not be exportedFailed to execute 'toDataURL' on 'HTMLCanvasElement'Failed to execute 'getImageData' on 'CanvasRenderingContext2D'Unable to get image data from canvas because the canvas has been tainted Meaning
To protect users' data, drawing a cross-origin image taints the canvas. The fix is to load the image with CORS: set img.crossOrigin = "anonymous" and make sure the image server sends Access-Control-Allow-Origin. Local file:// pages are also treated as cross-origin.
Common causes
- Image from a different domain drawn without
crossOrigin - Image server not sending
Access-Control-Allow-Origin - Page opened from
file:// - Image cached earlier without CORS headers
- Redirect to a non-CORS URL
⚡ Quick fix
- Set
img.crossOrigin = 'anonymous'beforeimg.src - Make the image server send
Access-Control-Allow-Origin: *(or your origin) - Serve images from your own domain/CDN with CORS
Detailed fix by platform
JavaScript
const img = new Image(); img.crossOrigin = 'anonymous'; img.src = url; img.onload = () => ctx.drawImage(img, 0, 0);
Nginx
location ~* \.(png|jpg|webp)$ { add_header Access-Control-Allow-Origin "*"; }
How to diagnose
- Origin — Is the image on another domain?
- Header — Does the image response include CORS?
- Cache — Cached without CORS earlier?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- $ is not defined Console: Uncaught ReferenceError: $ is not defined (jQuery not loaded or loaded after your code)
- Aw, Snap! Chrome: Aw, Snap! Something went wrong while displaying this webpage. Error code: STATUS_ACCESS_VIOLATION / SIGILL / Out of Memory
- captive portal Browser: This network requires you to sign in — captive portal (hotel, airport, café Wi-Fi) blocking HTTPS sites
Most viewed in Browser
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026