Categories
JavaScript Answers

How to fix getImageData() error The canvas has been tainted by cross-origin data with JavaScript?

Spread the love

To fix getImageData() error The canvas has been tainted by cross-origin data with JavaScript, we set the img element’s crossOrigin attribute.

For instance, we write

img.crossOrigin = "Anonymous";

to let us load cross origin images in an img element with JavaScript without getting cross origin errors.

This works for servers that has the Access-Control-Allow-Origin header set to '*'.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *