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

Recently getting errors while reading the cssRules

Open romanegloo opened this issue 6 years ago • 19 comments

Use case: description, code

I have been using domtoimage.toPng in my script, and recently I am seeing the following error message.

Error while reading CSS rules from chrome-extension://pioclpoplcdbaefihamjohnefbikjilc/content.css SecurityError: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules

A quick search gives me that: TL;DR: As of Chrome 64 you'll need to use a local development server to test functionality that depends on the CSS Object Model.

I am not sure if this is a bug due to this recent change, or mine. Any ideas?

Browsers

Chrome 65

romanegloo avatar Apr 06 '18 16:04 romanegloo

Have the same error in Chrome 65

zollero avatar Apr 11 '18 08:04 zollero

@romanegloo did you end up solving this? I'm experiencing the same issue in Chrome 66. Firefox appears to be fine.

I haven't worked to isolate the issue but it seems like it might be happening when there are images present in the DOM to be converted. This is a guess since my same code is working in other places where no images are present.

simon-lang avatar May 29 '18 02:05 simon-lang

In case the CSS is loaded via a link tag you can add crossorigin="anonymous" to solve this error in chrome.

MDSLKTR avatar Jun 06 '18 17:06 MDSLKTR

Having the same problem in Chrome 67. I did what @MDSLKTR said, but that didn't solve the issue. Works fine on FireFox.

sashatran avatar Jun 12 '18 22:06 sashatran

That fix does not work for me either.

@sashatran does the DOM that you're saving include images?

simon-lang avatar Jun 12 '18 23:06 simon-lang

Getting this error in local and prod environments. My DOM has SVG elements.

daiokaio avatar Jun 14 '18 18:06 daiokaio

@simon-lang no images, just a div element.

sashatran avatar Jun 15 '18 17:06 sashatran

I'm getting the same error in Chrome 68, both in local and production environments.

GabrielShaad avatar Aug 16 '18 14:08 GabrielShaad

I have the same probleme with both chrome and firefox for project with angular 7 that using material design and material icons Error while reading CSS rules from https://fonts.googleapis.com/icon?family=Material+Icons SecurityError: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules

FARHANE avatar Nov 20 '18 13:11 FARHANE

crossorigin="anonymous" worked in chrome Version 72.0.3626.109 (Official Build) (64-bit). Thanks @MDSLKTR

jsanjeev avatar Feb 15 '19 10:02 jsanjeev

@jsanjeev can you please explain the solution a bit.

zaidITpro avatar Jun 27 '19 10:06 zaidITpro

@zaidITpro you need to add crossorigin="anonymous" to the stylesheet for example <link href="https://fonts.googleapis.com/css?family=Nunito+Sans:700,900|Open+Sans|Open+Sans+Condensed:700" rel="stylesheet" crossorigin="anonymous">. You can read more on crossorigin here

MuthomiMate avatar Jul 17 '19 15:07 MuthomiMate

i try to add crossorigin="anonymous" to the link element, it works fine. Thank you~

zhouxiongking avatar Jun 04 '20 07:06 zhouxiongking

was not able remove it in nuxt + vuetify

BonBonSlick avatar Jul 28 '20 11:07 BonBonSlick

does the DOM that you're saving include images?

@simon-lang, I am using this package, getting the same error while I have IMG tag in my dom source element. Any ideas to solve this issue?

priyomukul avatar Dec 21 '20 03:12 priyomukul

我发现img标签内的src为空时会出现这个问题,不为空就正常

shanghaobo avatar May 17 '21 02:05 shanghaobo

In case the CSS is loaded via a link tag you can add crossorigin="anonymous" to solve this error in chrome.

This worked for me, thanks.

chaderenyore avatar Feb 14 '22 14:02 chaderenyore

@MDSLKTR crossorigin="anonymous" solves the issue in chrome. thanks, bud 👍

Gulshanaggarwal avatar Jun 08 '22 10:06 Gulshanaggarwal

Any idea for the case of google.maps that loads the styles from the script I can't take the screenshot Help me please

cfpenton avatar Oct 17 '22 14:10 cfpenton