Loading image from URL blocked by CORS
See original GitHub issueHi,
I’m using the loader to fetch image from server but I’m getting an error from the browser which saying accessing image has been blocked by CORS policy.
Even though I have specify crossOrigin
to true
but it doesn’t seems to do anything.
loader.add('image', 'https://pay.google.com/about/static/images/logos/apple_store.png', {crossOrigin: true})
Any idea how can I fix this problem?
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Dealing with image CORS error in Chrome, Chromium and ...
Access to image at '${url}' from origin '${origin}' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on ...
Read more >Allowing cross-origin use of images and canvas - HTML
HTML provides a crossorigin attribute for images that, in combination with an appropriate CORS header, allows images defined by the <img> ...
Read more >Html <img src=...> works but JS Image loading cause ...
I try to found solution my self (JS ES6) but find only-partially. We are able to load img from no-CORS support src into...
Read more >How to allow cross-origin use of images and canvas
The Image URL is been set to the. // src property of the image. img.src = imageUrl. // This function waits until the...
Read more >Cors Error on loading image
If the browser itself cannot upload a picture and swears at CORS, then CORS is not allowed. In the designer preview, it is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So the problem is that you are loading a cross-origin image, with a cross-origin policy set; but the server you are loading from is not setting cross origin headers. Browsers don’t allow this. It either has to be loaded with no crossOrigin policy, or the server has to allow cross-origin usage.
You can load the image as “dirty” meaning you don’t set the crossOrigin policy. This will dirty any canvas you try to draw it to, which usually only means you can’t read any pixels from it. If that is OK for your application, you can override the behavior to not set a policy like this:
The way the
crossOrigin
configuration works for a resource is:true
, then we will use'anonymous'
which is the defaultfalse
,undefined
,null
, etc), then the lib will auto-detect if the url is cross-origin and set the policy correctly.Please open a new issue with a repro case. Thanks!