bubkoo / html-to-image

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

CSS CORS Issue #301

Open ryanatearth opened 2 years ago

ryanatearth commented 2 years ago

I'm just starting to experiment with this library, as html2canvas is having some issues for me. The first thin I'm experiencing is a CSS CORS issue. The console debugger is throwing an error:

Error inlining remote css file SecurityError: CSSStyleSheet.cssRules getter: Not allowed to access cross-origin stylesheet

I'm not sure why this is happening, as any CSS that is associated with the DOM node I am trying to render to an image is only from my main domain. Not sure why a whole bunch of other CSS is trying to be parsed from this library. It appears that this library is trying to fetch and parse CSS files that are also included on the page, which I guess makes sense.

Is there a way to NOT have the library parse certain css files?

Here are a couple screenshots:

Screen Shot 2022-07-29 at 9 12 18 AM

Screen Shot 2022-07-29 at 9 12 30 AM

lisaschumann commented 2 years ago

I would second that. Is there not a way to just include specific styling rather than fetching it from the style sheets? Do not want to add crossorigin="anonymous" is possible.

vivcat[bot] commented 2 years ago

Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not-stale" to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.

Thanks for being a part of the Antv community! 💪💯

lisaschumann commented 2 years ago

I think this issue is still relevant!

watzon commented 1 year ago

This is definitely still an issue, does anyone have a workaround?

Gamewise commented 1 year ago

Yep still an issue for me. Any solutions that ppl have found?

Gamewise commented 1 year ago

Tried adding crossorigin="anonymous" to my css style links but that doesn't fix anything

PixtonMustafa commented 1 year ago

This issue also happens to me, any solution?

koosvanderkolk commented 1 year ago

Same issue here.

imrids commented 1 year ago

Issue also happens to me.

rahmanramsi commented 1 year ago

same issue to me

ahmedmukhtar1133 commented 1 year ago

Also having the same issue.

image
italomarcos1 commented 1 year ago

well be damned image

Gamewise commented 1 year ago

Hey folks, so I recently starting self-hosting all CSS (Google fonts etc.) and it fixed the issue. Probably just as well cos I discovered it's now illegal (in EU) to call in Google fonts as per normal, so you might as well bite the bullet and self-host.

longqioo commented 1 year ago

the Same issue;When will it be settled? Big God

born2net commented 1 year ago

same issue here, too bad as no longer usable this lib.

aleh-skrypko commented 1 year ago

+1, unusable

productdevbook commented 1 year ago

same problem :/

ljbqrn commented 1 year ago

[Still] Same issue here.

argarner commented 1 year ago

Even after embedding custom fonts as base64 strings, and only using local custom css for the html-to-image component, it still queries all remote assets embedded in the document head and beyond my control.

This library sorely needs the addition of a new option, that prevents all remote assets from being queried and generates the output regardless of remote (CSS or CORS) errors. Something like loadRemoteAssets: bool or an array of remote domains that can be safely queried.

walterwang commented 10 months ago

Adding crossorigin fixed it for me:

  <link rel="icon" type="image/x-icon" href="favicon.ico" crossorigin>
  <link rel="preconnect" href="https://fonts.googleapis.com" crossorigin>
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,500;0,600;0,700;0,800;1,300&display=swap" rel="stylesheet" crossorigin>
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" crossorigin>
brandoningli commented 5 months ago

Any news on this? Still experiencing this issue.