内容安全策略指令:;脚本src'self'blob:文件系统:chrome扩展资源:“;获取是否时

Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:" While fetching whether

本文关键字:资源 扩展 chrome 获取 是否 文件系统 blob 脚本 安全策略 src self      更新时间:2023-09-26

我正在使用jQuery simple是否插件来获取是否,并试图创建一个chrome小部件。

在将文件加载为chrome扩展名时,我遇到了错误,在查看了谷歌提供的所有帮助后,我仍然无法解决这个问题。

以下是雅虎是否的错误

> jquery-2.1.3.min.js:4 Refused to load the script
> 'https://query.yahooapis.com/v1/public/yql?format=json&rnd=2016437&diagnosti…ces(1)%20where%20text=%22New%20Delhi%22)%20and%20u=%22c%22&_=1462326587463'
> because it violates the following Content Security Policy directive:
> "script-src 'self' blob: filesystem: chrome-extension-resource:".

另一个错误是字体,

> Refused to load the font
> 'data:application/octet-stream;base64,AAEAAAAPAIAAAwBwR1NVQrD+s+0AAAD8AAAAQk…GIUViwQIhYsQNkRLEmAYhRWLoIgAABBECIY1RYsQMARFlZWVmzDAIBDCq4Af+FsASNsQIARAAA'
> because it violates the following Content Security Policy directive:
> "default-src *". Note that 'font-src' was not explicitly set, so
> 'default-src' is used as a fallback.

使用的舱单代码是

"content_security_policy": "script-src 'self'; object-src 'self' https://query.yahooapis.com/",
    "permissions": [
      "tabs", "<all_urls", "http://localhost/",
      "http://*/*", "https://*/*", "https://query.yahooapis.com/*"
    ],
    "content_scripts":
    [{
        "css": [
            "css/component.css",
            "css/tooltip-line.css",
            "css/modal.css"
        ],
        "js": [
            "js/modernizr.custom.js",
            "js/jquery-2.1.3.min.js",
            "js/jquery.simpleWeather.min.js",
            "js/handlebars-v4.0.5.js",
            "js/moment.min.js",
            "js/background.js"
        ],
        "matches": [ "http://*/*", "https://*/*"]
    }]

此外,在我的html文件中,我正在使用这个元标签

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'" />

有人能帮我解决这个问题吗。

您的内容安全策略具有"script-src 'self',这意味着无法从第三方URL加载脚本。

您已经在object-src指令中指定了yahoo API。object-src指令(MDN)为<object><embed><applet>元素指定有效的源。

要从第三方加载脚本,必须在script-src指令中指定如下:

"content_security_policy": "script-src https://query.yahooapis.com/ 'self'; ..."