【问题标题】:Chrome App : Refused to execute inline script because it violates the following Content Security Policy directiveChrome 应用程序:拒绝执行内联脚本,因为它违反了以下内容安全策略指令
【发布时间】:2017-07-19 04:38:36
【问题描述】:

我对同一线程进行了一些研究,并尝试了我得到的答案。但是,每次都会抛出相同的错误。

在我的例子中,它是一个 chrome 应用程序,在一个页面上我使用 iframe,我将 src 指向一些 XHTML 内容。这实际上包含一些我无法删除或更改的内联样式和脚本。

下面是我的清单文件。

{
    "manifest_version": 2,
    "name": "*****",
    "short_name": "****",
    "version": "*****",
    "permissions": [""],
    "content_security_policy": "default-src 'self' 'unsafe-inline' 'unsafe-eval'; script-src 'unsafe-inline' 'unsafe-eval' 'self'; object-src 'self' 'unsafe-inline' 'unsafe-eval'",
    "app": {
        "background": {
            "scripts": ["chrome.js"]
        }
    },
    "icons": {
        "16": "1.png",
        "48": "2.png",
        "128": "3.png"
        },
    "sandbox": {
        "pages": [
            "****.html"
        ]
    }
}

【问题讨论】:

标签: jquery google-chrome google-chrome-app content-security-policy chrome-app-developer-tool


【解决方案1】:

请参考Content Security Policy guidelines

内联脚本

在 Chrome 45 之前,没有机制可以放松 限制执行内联 JavaScript。特别是, 设置包含“unsafe-inline”的脚本策略将没有 效果。

从 Chrome 46 开始,可以通过指定 策略中源代码的 base64 编码哈希。这个哈希必须 以使用的哈希算法(sha256、sha384 或 sha512)作为前缀。看 以元素的哈希用法为例。

【讨论】:

  • 我在 chrome 51 时发布了这个应用程序,那个时候相同的清单配置工作正常。那么你是说散列是唯一的解决方案吗?
  • 更多来自 xhtml 的脚本是动态的。
  • 可能显示您尝试加载的 html 并说明您是如何加载它的?
  • main html --------------- 文档 xyz.xhtml --------------- Document .asdsd{ text-shadow: 0px 0px 1px rgba(0,0,0,0.1) }
    ---
  • 不是通过 https 加载的吗?
猜你喜欢
  • 1970-01-01
  • 2021-07-26
  • 2013-07-13
  • 2017-05-24
  • 1970-01-01
  • 2013-07-19
  • 2023-02-25
  • 2015-09-21
相关资源
最近更新 更多