【问题标题】:How do I use YUI3 in a Chrome extension?如何在 Chrome 扩展程序中使用 YUI3?
【发布时间】:2013-02-04 16:52:51
【问题描述】:

如果我下载缩小的 YUI3 加载器并将其包含在我的 background.html 中,我会收到以下错误:

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

可以在扩展中使用YUI3吗?

【问题讨论】:

    标签: google-chrome-extension yui


    【解决方案1】:

    它似乎阻止您使用 eval()。确保清单中有以下行。

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

    【讨论】:

      【解决方案2】:

      这就是我能够做到的。从 git 克隆 yui3 和 yui3-gallery,在我的扩展树中添加我需要的模块。然后从 popup.html 和 background.html 加载 config.js。该文件如下所示:

      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" }
                  }
              }
          }
      };
      

      现在一切正常!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-07-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多