为什么我得到 "Failed to load extension. Invalid value for 'content_security_policy'"?

Why am I getting "Failed to load extension. Invalid value for 'content_security_policy'"?

我正在尝试创建一个 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"
    }
    ]
}

加载扩展失败并显示消息

Failed to load extension
File
~\alert-beep
Error
Invalid value for 'content_security_policy'.
Could not load manifest.

我做错了什么?

我研究了 CSP 的 chrome 扩展(去 here 了解清单 v3 的更多信息)。

使用

"content_security_policy": {
  "extension_pages": "script-src 'self'; object-src 'self'"
}

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

清单 v3

"content_security_policy": {
    "extension_pages": "script-src 'self'; object-src 'self'; script-src-elem 'self' 'unsafe-inline' https://music.yandex.ru/;"
}

由于manifest现在更新到V3,content_security_policy是一个字典。在这种情况下,您应该更改此行

"content_security_policy": "script-src 'self'; object-src 'self'",

至此

"content_security_policy": {
    "script-src": 'self',
    "object-src": 'self'
 }

在此处阅读更多内容:https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#content-security-policy