【问题标题】:Manifest version 2 for news reader新闻阅读器的清单版本 2
【发布时间】:2015-05-21 05:02:43
【问题描述】:

我正在尝试从 chrome 示例扩展中安装 news reader

但即使不进行更改,它也无法正常工作。所以因为它需要清单 v2,所以我将 manifest_version: 2 添加到清单中,这给了我以下信息:

{
  "name": "__MSG_name__",
  "version": "1.1",
  "manifest_version": 2,
  "description": "__MSG_description__",
  "icons": { "128": "news_icon.png" },
  "browser_action": {
    "default_title": "__MSG_default_title__",
    "default_icon": "news_action.png",
    "default_popup": "feed.html"
  },
  "permissions": [
    "tabs",
    "http://news.google.com/*",
    "http://news.google.es/*"
  ],
  "default_locale": "en"
}

但是我将如何更新它以修复以下错误:

feed.html:75 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

feed.html:103 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

feed.html:308 Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

【问题讨论】:

  • Lopk 在清单文档中。有权限。

标签: javascript html css google-chrome google-chrome-extension


【解决方案1】:

内容安全政策文档中有一个handy guide。里面还提到,内联脚本的情况下不能通过修改CSP本身来解决。

具体请阅读inline scripts 部分。

简而言之,您的情况需要进行以下更改(基于错误):

  • 如果有任何<script> /* some code */ </script> 块,则需要将它们移动到单独的文件中并使用<script src="file.js"></script> 加载

  • 如果有像<div onclick="clickHandler()"><body onload="load()">这样的内联处理程序,则需要将它们转换为addEventListener格式并从包含的JS代码中执行。有关示例,请参阅文档。

不要犹豫,在https://crbug.com 提出错误,以表明样本已过期。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-04
    • 2013-02-15
    • 2012-08-02
    • 1970-01-01
    • 2016-09-15
    • 1970-01-01
    • 2012-08-02
    • 2016-11-12
    相关资源
    最近更新 更多