Git Product home page Git Product logo

Comments (7)

cyberalien avatar cyberalien commented on May 30, 2024 1

It isn't possible because it would break backwards compatibility. Some users might rely on that stylesheet being injected.

If you really want to get rid of that message, the only option is to build custom version of Iconify. Clone this repository, open src/browser/init.js, remove this code:

    /**
     * Add stylesheet
     *
     * @param timed
     * @returns {boolean}
     */
    local.addStylesheet = function(timed) {
        var el;

        if (!document.head || !document.body) {
            if (local.domready) {
                // head or body is missing, but document is ready? weird
                return true;
            }
            if (!timed) {
                local.initTimeout(local.addStylesheet.bind(null, true));
            }
            return false;
        }

        // Add Iconify stylesheet
        try {
            el = document.createElement('style');
            el.type = 'text/css';
            el.innerHTML = 'span.iconify, i.iconify, iconify-icon { display: inline-block; width: 1em; }';
            if (document.head.firstChild !== null) {
                document.head.insertBefore(el, document.head.firstChild);
            } else {
                document.head.appendChild(el);
            }
        } catch (err) {}

        return true;
    };
    local.initQueue.push(local.addStylesheet.bind(null, false));

then rebuild package. To rebuild it run these commands:

npm install
npm run build

Then you can use iconify.min.js from directory dist

from iconify.

cyberalien avatar cyberalien commented on May 30, 2024

This is interesting. I'll need to investigate this new Chrome thing.

Currently inline style is used for 2 purposes:

  • To add transform: rotate(360deg) that seems redundant, but it is actually needed to fix rendering bug in Firefox.
  • To add vertical-align: -0.125em that makes icon behave like icon font.

Rendering bug that required dummy transform is no longer needed. Just few years ago it existed in almost all browsers, but all vendors have fixed it. Firefox was last one to fix it just few months ago.

Vertical alignment is needed. However it can be moved from inline style to setting it in DOM: node.style.verticalAlign = '-0.125em';. I don't know if that would fix error, will need to investigate it.

from iconify.

haacked avatar haacked commented on May 30, 2024

To add transform: rotate(360deg) that seems redundant, but it is actually needed to fix rendering bug in Firefox.

😆 This reminds me of a famous Jason Kidd quote.

Jason-Kidd

I don't know if that would fix error, will need to investigate it

I believe that would fix the error as DOM manipulation doesn't violate CSP. Just setting inline styles does.

from iconify.

cyberalien avatar cyberalien commented on May 30, 2024

Managed to get that error as well, played a bit with it and found a fix. You are right, DOM manipulation doesn't violate CSP, so workaround works.

I'll apply fix, will do some more tests to make sure it all works and will publish update tomorrow.

For allowed script sources you also need to add https://api.iconify.design/. Script uses JSONP to retrieve data for icons instead of fetching JSON because it is easier to support Internet Explorer that way, so it needs to be added to script-src policy.

If you'll be updating to Iconify 2 when it will be available (I think it will be ready sometime in April, though could be delayed a bit because tons of documentation needs to be written), things will get a bit more complicated. You'll need to add 2 more domains to script-src: https://api.simplesvg.com/ and https://api.unisvg.com/. Why are there 3 domains instead of one? Sometimes visitors experience routing issues or DNS issues or API could be down for few minutes. Internet is not stable and things can happen. To solve that issue, new version has redundancy built in to connect to backup API if default API can't be reached within a second.

from iconify.

haacked avatar haacked commented on May 30, 2024

Sounds good! 👍

from iconify.

cyberalien avatar cyberalien commented on May 30, 2024

Published version 1.0.5 with fix.

You will still see one CSP notice in console. Script will attempt to inject the following stylesheet:

span.iconify, i.iconify, iconify-icon { display: inline-block; width: 1em; }

It will fail and display notice in console, but it will not affect any functionality and will not stop execution.

from iconify.

Juneezee avatar Juneezee commented on May 30, 2024

@cyberalien Hi, in version 1.0.5, I still get one style-src error about unsafe-inline. Is it possible not to set or inject any style to avoid this error?

image

EDIT: The error comes from this line in iconify.js
image

Thanks

from iconify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.