question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loading image from URL blocked by CORS

See original GitHub issue

Hi,

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:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
englercjcommented, Aug 22, 2018

image

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:

.add('https://some-cross-origin.com/image.png', { crossOrigin: '' })

The way the crossOrigin configuration works for a resource is:

  • If it is true, then we will use 'anonymous' which is the default
  • If it is any other non-string type (false, undefined, null, etc), then the lib will auto-detect if the url is cross-origin and set the policy correctly.
  • If it is a string value, then the lib will use the string value as the policy. An empty string is “no policy”.
0reactions
englercjcommented, Apr 14, 2020

Please open a new issue with a repro case. Thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found