为什么我收到“无法加载扩展。‘content_security_policy’值无效”?

DeL*_*n88 14 javascript google-chrome-extension manifest.json

我正在尝试创建一个 chrome 扩展。我的清单文件是

{
    "name": "Alert-Beep",
    "action": {},
    "manifest_version": 3,
    "version": "0.1",
    "description": "Beeps if alert() is called",
    "content_security_policy": "script-src 'self'; object-src 'self'",
    "permissions": [
    "activeTab",
    "scripting"
    ],
    "content_scripts": [
    {
        "matches": ["https://*.com/*"],
        "js": ["alert-beep.js"],
        "run_at": "document_start"
    }
    ]
}
Run Code Online (Sandbox Code Playgroud)

加载扩展失败并显示消息

Failed to load extension
File
~\alert-beep
Error
Invalid value for 'content_security_policy'.
Could not load manifest.
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Иль*_*шко 22

另一个对我有帮助的例子:

清单 v3

"content_security_policy": {
    "extension_pages": "script-src 'self'; object-src 'self'; script-src-elem 'self' 'unsafe-inline' https://music.yandex.ru/;"
}
Run Code Online (Sandbox Code Playgroud)


小智 6

我研究了 chrome 扩展的 CSP(请转到此处了解有关清单 v3 的更多信息)。

使用

"content_security_policy": {
  "extension_pages": "script-src 'self'; object-src 'self'"
}
Run Code Online (Sandbox Code Playgroud)