bubkoo / html-to-image

✂️ Generates an image from a DOM node using HTML5 canvas and SVG.
MIT License
5.69k stars 531 forks source link

Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules #362

Open eyunhua opened 1 year ago

eyunhua commented 1 year ago

Expected Behavior

Html-to-image as part of these functions, they are packaged into sdk. When other projects call sdk, an error is reported as follows: image

Current Behavior

Console report an error

Steps To Reproduce

  1. introduce html-to-image into the project
  2. packed as sdk output
  3. other projects introduce sdk
  4. click the button to call html-to-image in other projects

Your Environment

vivcat[bot] commented 1 year ago

👋 @eyunhua

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

AndrewN93 commented 1 year ago

This worked in my case - https://github.com/bubkoo/html-to-image/issues/49#issuecomment-762222100

lalit7788 commented 1 year ago

Any update on this problem?

Even with the crossorigin="anonymous" I am getting these errors:

Error inlining remote css file DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules

Access to fetch at 'https://use.fontawesome.com/releases/v5.0.7/css/all.css' from origin 'http://localhost:3000' 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.

Error loading remote stylesheet TypeError: Failed to fetch

lalit7788 commented 1 year ago

Update: setting skipFonts to true removed all of the error messages and the resulting image still looks the same.

petrgazarov commented 1 year ago

Also getting this error. Seems like skipFonts: true just hides the problem. The fonts in the screenshot are inaccurate.

Original:

Conduit

Screenshot:

about_blank
DivyaShikha-Singh commented 6 months ago
    skipFonts: true,
    preferredFontFormat: 'woff2',
    backgroundColor: 'white'

This helped me to get rid of all the console errors related to css and scripts from the library

leoatfentech commented 3 weeks ago

Any news about this bug ? I've seen that a PR was still open, nay plan to merge it ?