How to migrate manifest version 2 to v3 for chrome extension?

I was looking for the same thing. Thanks to the help of the user wOxxOm I’ve figured out what to change inside the manifest file. Here is an example of how to migrate manifest.json from v2 to v3.

First thing is to change the manifest_version key from 2 to 3

//Manifest v2
"manifest_version": 2

//Manifest v3
"manifest_version": 3

As written into the manifest migration guidelines, pageAction and browserAction API will be unified under the action API. This means that you need to change browser_action and page_action keys into action

//Manifest v2
"browser_action": {...}
"page_action": {...}

//Manifest v3
"action": {...}

Background pages and background scripts are deprecated into manifest v3. They are replaced from service workers. This means that the background section of the manifest file needs to be modified in this way

//Manifest v2
"background": {
 "scripts": ["js/background.js"]
}

//Manifest v3
"background": {
 "service_worker": "js/background.js"
}

To declare the packed resources that needs to be accessed from the web, the web_accessible_resources needs to be changed in this way

//Manifest v2
"web_accessible_resources": [
        "js/options.js",
        "js/main.js",
        "js/injected.js"
]

//Manifest v3
"web_accessible_resources": [{
 "resources": ["js/options.js","js/main.js","js/injected.js"],
 "matches": [],
 "extension_ids": []
}]

Content security policy in v3 is an object

//Manifest v2
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'" 

//Manifest v3
"content_security_policy": {
 "extension_pages": "script-src 'self' 'unsafe-eval'; object-src 'self'",
 "sandbox": "..."
}

To have more information about you can check this link or this one.

Leave a Comment