An image can look correct in a page and still fail when an editor tries to read its pixels. You may see a remote photo on screen, draw it onto a canvas, and then get a SecurityError from getImageData() or toDataURL(). The request succeeded. The browser is enforcing a separate rule for reading the pixels.
Disclosure: I’m the founder of MediaToURL. This is general browser guidance, and a media URL provider cannot override another server’s CORS policy.
Displaying an image is different from reading it
A browser can display an ordinary cross-origin image while restricting scripts from inspecting its pixel data. If you draw that image onto a canvas without an approved Cross-Origin Resource Sharing (CORS) response, the canvas becomes tainted. The drawing may work, while pixel-reading and export methods fail. MDN explains the cross-origin image rules for canvas.
That distinction matters in crop tools, color pickers, thumbnail generators, and any workflow that exports a canvas. Seeing the image is not proof that your script can inspect it.
Request CORS before the image starts loading
Set the image's crossOrigin property before assigning src. For a public image that does not need cookies or other credentials, anonymous mode is usually the right starting point.
const image = new Image(); image.crossOrigin = "anonymous"; image.addEventListener("load", () => { const canvas = document.querySelector("#preview"); const context = canvas.getContext("2d"); canvas.width = image.naturalWidth; canvas.height = image.naturalHeight; context.drawImage(image, 0, 0); try { const firstPixel = context.getImageData(0, 0, 1, 1); console.log(firstPixel.data); } catch (error) { console.error("Canvas pixels are not readable", error); } }); image.addEventListener("error", () => { console.error("Image load failed. Check the URL and CORS response."); }); image.src = "https://assets.example.com/photo.webp"; ~~~{% endraw %} The image host must also allow your app's origin in its response. For example, a server might return:{% raw %} ~~~http Access-Control-Allow-Origin: https://app.example.com ~~~ A public image without credentials may use an Access-Control-Allow-Origin value of * if that matches the host's policy. When you request an image in CORS mode and the server does not grant access, the browser blocks that load. The page cannot add permission to the remote server's response from client-side JavaScript. See MDN's reference for the [crossorigin attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/crossorigin). ## Check the response in DevTools When the result is unexpected, open the Network panel, reload the page, and select the image request. Check four things: 1. Confirm the final URL is the image you intended. A redirect can land on a share page, login screen, or a different host. 2. Check the response status and Content-Type. A successful HTML page is still not an image response. 3. Look for Access-Control-Allow-Origin in the response headers. The allowed origin must match your app, unless the host intentionally allows all origins for a public file. 4. Read the console message alongside the request. It usually tells you whether the browser rejected the CORS check or the file failed for another reason. If you only need to show a picture, an ordinary image element may be enough. If the feature needs to crop, sample, or export pixels, the host must return a CORS-enabled response. The browser cannot grant that permission on the host's behalf. MDN's [getImageData() documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getImageData) describes the SecurityError that can appear when the canvas is not readable. Two common fixes do not solve this. Setting crossOrigin after src is too late because the request has already started. Adding Access-Control-Allow-Origin as a request header from JavaScript also does not work; it is a response header the server must send. Using fetch with mode set to no-cors does not make the response readable either. 
