【问题标题】:Chrome extension manifest v3 and inline scriptsChrome 扩展清单 v3 和内联脚本
【发布时间】:2021-09-21 21:04:57
【问题描述】:

构建 chrome 扩展。我需要在页面内添加脚本以重新声明预定义的函数(例如 fetch())。 要加载的脚本是扩展文件的一部分。我之前所做的只是将脚本加载到页面中包含的标签上。现在,当我尝试时,我有这个:

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

试图将其添加到清单中

"content_security_policy": {
  "extension_pages": "script-src 'self' 'sha256-...",
  "sandbox": "none"
}

得到错误:

Insecure CSP value "'sha256-...'" in directive 'script-src'.

与“nonce-”或“unsafe-inline”相同,它们都被命名为不安全,我无法使用此类策略加载清单。 那么我现在应该如何处理 manifest v3 呢?

【问题讨论】:

  • 不要使用内联脚本。您可以在单独的文件中执行完全相同的操作。

标签: javascript google-chrome-extension content-security-policy


【解决方案1】:

content_security_policy 的“sha-..”、“nonce-..”和“unsafe-inline”解决方法在清单 3 中不再有效

【讨论】:

    【解决方案2】:

    嗯。为什么我没有得到自己?是的,我可以将这些脚本添加为文件,而不是它们的内联内容。感谢您的帮助 wOxxOm

    【讨论】:

      猜你喜欢
      • 2021-07-30
      • 2022-12-15
      • 1970-01-01
      • 2018-12-03
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 2022-11-15
      • 2011-09-28
      相关资源
      最近更新 更多