首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >拒绝加载脚本,因为它违反了以下内容安全策略指令:" script -src 'self‘

拒绝加载脚本,因为它违反了以下内容安全策略指令:" script -src 'self‘
EN

Stack Overflow用户
提问于 2013-07-16 06:19:06
回答 3查看 26.3K关注 0票数 4

我正在尝试开发一个铬应用程序,在这个应用程序中,我想显示一个定制的Rss提要,但是提要不会像上面那样加载和消除错误。 显示的错误详细信息

代码语言:javascript
复制
Refused to load the script
 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'
 because it violates the following Content Security Policy directive:
 "script-src 'self'
 https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js".

     Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'
 https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js". 
 jquery.min.js:35

     Refused to load the script 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'
 because it violates the following Content Security Policy directive:
 "script-src 'self'
 https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js".

     Refused to load the script 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=2&output=json&q=http%3A%2F%2Fblog.tax2290.com%2Ffeed%2F&hl=en&callback=jsonp1373953012503'
 because it violates the following Content Security Policy directive:
 "script-src 'self'
 https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js".

manifest.json

代码语言:javascript
复制
{
      "name": "Tax New 2290",
      "manifest_version": 2,
      "version": "1.1",
      "description": "Tax 2290",
    "web_accessible_resources": ["images/logo.png"],
      "icons": {
        "16": "icon16.png",
        "19":"icon19.png",
        "48": "icon48.png",
        "128": "icon128.png",
        "256": "icon256.png"
    },
     "browser_action":
    {
    "default_icon":"images/logo.png",
    "default_popup":"index.html"
    },

         "permissions": ["tabs", "<all_urls>","http://www.tax2290.com","http://*/*", "https://*/*","http://*.google.com/"],
        "content_security_policy": "script-src 'self' https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js; https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js; object-src 'self'"

    }

index.html

代码语言:javascript
复制
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="images/feed.js"></script>
<link rel="stylesheet" href="images/style.css" type="text/css"  />
<title>Chrome Popup</title>
</head>

feed.js

代码语言:javascript
复制
        $(function() {
                var $items = $('#vtab>ul>li');
                $items.mouseover(function() {
                    $items.removeClass('selected');
                    $(this).addClass('selected');

                    var index = $items.index($(this));
                    $('#vtab>div').hide().eq(index).show();
                }).eq(0).mouseover();
            });


    $(document).ready(function () {  
       $('#divRss2').FeedEk({
            FeedUrl: 'http://blog.tax2290.com/feed/',
            MaxCount: 2,ShowDesc: true,
            ShowPubDate: true,
            DescCharacterLimit: 250
        });
    });


   > Please tel me how could avoid these errors and load the custom RSS feeds.
EN

回答 3

Stack Overflow用户

发布于 2016-01-18 18:25:23

您的"content_security_policy“有几个问题。

1)首先,您应该删除1.4.1和1.9.1jQuery声明之间的分号。多个URL应仅用一个空格分隔,而不使用其他字符。

2)第二种情况是,您正在尝试加载这个脚本"http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=2&output=json&q=http%3A%2F%2Fblog.tax2290.com%2Ffeed%2F&hl=en&callback=jsonp1373953012503“,但在您的CSP中从来不允许这样做。

第三,似乎需要允许内联脚本。

我会把你的"content_security_policy“改为:

代码语言:javascript
复制
"content_security_policy": "script-src 'self' https://ajax.googleapis.com/ 'unsafe-inline'; object-src 'self'"

“不安全-内联”应修复“拒绝执行内联脚本”错误。

https://ajax.googleapis.com/应该允许jquery的两个版本加载以及/ajarx/services/feed/load URL。

票数 2
EN

Stack Overflow用户

发布于 2013-07-18 19:53:36

如果您构建了一个打包的应用程序,则无法加载外部脚本。您的应用程序必须嵌入每个脚本、样式或图像。

检查此链接以确保您遵循铬应用CSP规则:https://developer.chrome.com/extensions/contentSecurityPolicy

票数 1
EN

Stack Overflow用户

发布于 2021-10-31 22:54:55

首先,尝试将此部分从清单文件中删除。

代码语言:javascript
复制
"content_security_policy": "script-src 'self' https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js; https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js; object-src 'self'"

然后下载到本地环境文件夹的所有外部链接,然后在那里引用它。

例如,将https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js下载到父文件夹并从

代码语言:javascript
复制
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>

代码语言:javascript
复制
<script src="jquery.min.js"></script>

此外,我建议将所有引用从head标记移到body标记的底部。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17669359

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档