html-to-image icon indicating copy to clipboard operation
html-to-image copied to clipboard

CSS CORS Issue

Open ryanatearth opened this issue 2 years ago • 23 comments

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

ryanatearth avatar Jul 29 '22 16:07 ryanatearth

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.

lisaschumann avatar Aug 05 '22 11:08 lisaschumann

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! 💪💯

biiibooo[bot] avatar Aug 26 '22 02:08 biiibooo[bot]

I think this issue is still relevant!

lisaschumann avatar Aug 26 '22 07:08 lisaschumann

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

watzon avatar Sep 20 '22 15:09 watzon

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

Gamewise avatar Sep 29 '22 03:09 Gamewise

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

Gamewise avatar Sep 29 '22 03:09 Gamewise

This issue also happens to me, any solution?

PixtonMustafa avatar Oct 04 '22 03:10 PixtonMustafa

Same issue here.

koosvanderkolk avatar Nov 09 '22 16:11 koosvanderkolk

Issue also happens to me.

imrids avatar Nov 11 '22 18:11 imrids

same issue to me

rahmanramsi avatar Nov 16 '22 00:11 rahmanramsi

Also having the same issue. image

ahmedmukhtar1133 avatar Nov 17 '22 09:11 ahmedmukhtar1133

well be damned image

italomarcos1 avatar Nov 30 '22 03:11 italomarcos1

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.

Gamewise avatar Nov 30 '22 05:11 Gamewise

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

longqioo avatar Dec 13 '22 09:12 longqioo

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

born2net avatar Jan 06 '23 08:01 born2net

+1, unusable

aleh-skrypko avatar Jan 30 '23 16:01 aleh-skrypko

same problem :/

productdevbook avatar Feb 01 '23 07:02 productdevbook

[Still] Same issue here.

ljbqrn avatar Feb 13 '23 01:02 ljbqrn

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.

argarner avatar Feb 21 '23 00:02 argarner

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>

walterwang avatar Oct 27 '23 02:10 walterwang

Any news on this? Still experiencing this issue.

brandoningli avatar Mar 28 '24 21:03 brandoningli