Open Ianec21 opened 9 months ago
it seems not to be related to this React implementation but an issue from "html-to-image". Could you give it a look?
@Ianec21 can you show how you are converting div to image? It should directly return you a base64 data I think
+1 same exact issue
@Ianec21 @bridger217 could you provide a reproducible example to help looking into the issue?
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)
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 :)
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?
Link to Reproduction
-
Steps to reproduce
Version
latest
Browser
Google Chrome
Operating System
Additional Information
None.