Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Firefox getCssRules fails for external stylesheets #13

Closed
ghispi opened this issue Nov 9, 2015 · 4 comments
Closed

In Firefox getCssRules fails for external stylesheets #13

ghispi opened this issue Nov 9, 2015 · 4 comments
Assignees
Labels

Comments

@ghispi
Copy link

ghispi commented Nov 9, 2015

In firefox (41.0.2) getCssRules fails for stylesheets from external domains.

SecurityError: The operation is insecure.
util.asArray(sheet.cssRules || []).forEach(cssRules.push.bind(cssRules));

In particular it failed on such link:

<link href="//fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600" rel="stylesheet">
@ghispi
Copy link
Author

ghispi commented Nov 9, 2015

To workaround this I've applied such fix:

            function getCssRules(styleSheets) {
                var cssRules = [];
                var anchor = document.createElement('a');
                styleSheets.forEach(function (sheet) {
                    anchor.href = sheet.href;
                    if (anchor.hostname === window.location.hostname) {
                        util.asArray(sheet.cssRules || []).forEach(cssRules.push.bind(cssRules));
                    }
                });
                return cssRules;
            }

@ghispi ghispi changed the title IN FIrefox getCssRules fails for external stylesheets In Firefox getCssRules fails for external stylesheets Nov 10, 2015
@tsayen
Copy link
Owner

tsayen commented Nov 11, 2015

Hi! Thanks for reporting. Seems to me that your patch kind of skips the potentially problematic stylesheets. That could work, if the stylesheet you are skipping doesn't contain anything essential for the rendering itself, otherwise the rendered image will look differently. That also may be the only available workaround. I'll take a closer look at it

@tsayen tsayen added the bug label Nov 11, 2015
@tsayen tsayen self-assigned this Nov 11, 2015
@ghispi
Copy link
Author

ghispi commented Nov 11, 2015

Well that was the only thing I found at the moment. Tomorrow I'll play with cross origin policy.
https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy#Cross-origin_network_access says that it should work with current code if the stylesheet has Content Type defined, type attrib which that particular link lacked. Although doc says it vary between browsers. Though this might give some clues for you.

@tsayen
Copy link
Owner

tsayen commented Nov 29, 2015

Hi, in 1.0.5 I've added try/catch&log around the code that might throw that error. Don't know if that should remain there permanently, but let it be like that for now. If you're still interested in that issue, let me know what you think about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants