Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS Error #101

Open
1 of 3 tasks
Ianec21 opened this issue Feb 1, 2024 · 5 comments
Open
1 of 3 tasks

CORS Error #101

Ianec21 opened this issue Feb 1, 2024 · 5 comments

Comments

@Ianec21
Copy link

Ianec21 commented Feb 1, 2024

Description

When I am trying to convert my div into an image, I receive this error. I am getting images from firebase bucket storage. Can I somehow put no-cors argument in the fetch method?

Access to fetch at 'https://firebasestorage.googleapis.com/v0/b/testmd-21f8a.appspot.com/o/images%2Fimagini-itemi%2F1706719835228Item%202%20Bac-01.jpg?alt=media&token=b7845988-f909-4ac3-b856-037a77f46ffd' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Link to Reproduction

Steps to reproduce

  1. Create an div.
  2. Try to convert the div to an image.

Version

latest

Browser

Google Chrome

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

None.

@hugocxl
Copy link
Owner

hugocxl commented Feb 8, 2024

it seems not to be related to this React implementation but an issue from "html-to-image". Could you give it a look?

@xandemon
Copy link

@Ianec21 can you show how you are converting div to image? It should directly return you a base64 data I think

@bridger217
Copy link

+1 same exact issue

@hugocxl
Copy link
Owner

hugocxl commented May 31, 2024

@Ianec21 @bridger217 could you provide a reproducible example to help looking into the issue?

@Meriku
Copy link

Meriku commented Aug 3, 2024

Hello everyone,

I've encountered a similar issue and spent a few days resolving it, so I wanted to share some information.

When an image is displayed in a component using the <img> tag with a URL to the source, the browser does not check CORS policies or make a preflight request source. However, when react-to-image tries to build an image from the component, it makes an explicit fetch to the source using the GET method. By default, the browser expects to receive an Access-Control-Allow-Origin header in the response. While the image can be shown in an <img> tag, react-to-image fails to build the image from the component due to CORS restrictions. (code attached)
image

I'm using an AWS S3 bucket with CloudFront. In my case, I added a "SimpleCORS" response headers policy to force CloudFront to include the Access-Control-Allow-Origin header in every response, and it seems to be working fine now.
I have no idea if it is possible to fix on the library side (as no-cors restricts the usage of response body in js code)

Hope this info will be helpful to someone :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants