How do I use YUI3 in a Chrome extension?

痞子三分冷 提交于 2019-12-24 02:58:27

问题


If I download the minified YUI3 loader and include it in my background.html I get the following error:

Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:".

Can YUI3 be used in an extension?


回答1:


It looks like it's blocking you from using eval(). Make sure you have the following line in your manifest.

"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"




回答2:


This is how I was able to do it. Clone yui3 and yui3-gallery from git and in my extension tree, add the modules I need. Then load config.js from popup.html and background.html. The file looks like this:

YUI_config = {
    filter: "raw",
    base: "yui3/build/",
    root: "yui3/build/",
    comboBase: "/combo?",
    combine: false,
    groups: {
        gallery: {
            base: "yui3-gallery/build/",
            root: "yui3-gallery/build/",
            comboBase: "/combo?",
            combine: false,
            patterns: {
                "gallery-": {},
                "gallerycss-": { type: "css" }
            }
        }
    }
};

Now it all works!



来源:https://stackoverflow.com/questions/14967130/how-do-i-use-yui3-in-a-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!