11

I am trying to create a chrome extension. My manifest file is

{
    "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"
    }
    ]
}

Loading the extension fails with the message

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

What am I doing wrong?

DeLorean88
  • 547
  • 2
  • 5
  • 15
  • See the [migration guide](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#fcontent-security-policy): CSP is now a dictionary object. – wOxxOm Apr 17 '21 at 02:51
  • 1
    Thanks. I also found this answer to be helpful https://stackoverflow.com/questions/63308160/how-to-migrate-manifest-version-2-to-v3-for-chrome-extension – DeLorean88 Apr 17 '21 at 14:30

3 Answers3

21

An additional example that helped me:

manifest v3

"content_security_policy": {
    "extension_pages": "script-src 'self'; object-src 'self'; script-src-elem 'self' 'unsafe-inline' https://music.yandex.ru/;"
}
Chris McFarland
  • 6,059
  • 5
  • 43
  • 63
5

I've looked into CSP for chrome extensions (go here to learn more for manifest v3).

Use

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

Since manifest is now updated to V3, content_security_policy is a dictionary. in this case, you should change this line

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

to this

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

read more here: https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#content-security-policy

YU XI ONG
  • 59
  • 5