Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I can't get my head around how to upgrade my chrome extension manifest v2 to v3

I checked https://developer.chrome.com/extensions/migrating_to_manifest_v3 but it doesn't talk about the manifest.json

any idea what it needs to be changed in my manifest here :-

    "name": "My Extension",
    "version": "1.0.0",
    "short_name": "Ex",
    "author": "User",
    "description": "cool chrome ex",
    "browser_action": {
        "default_title": "ex",
        "default_icon": "img/logo.png"
    },
    "options_page": "options.html",
    "options_ui": {
        "page": "options.html",
        "open_in_tab": true
    },
    "background": {
        "scripts": [
            "js/background.js"
        ]
    },
    "permissions": [
        "tabs",
        "background",
        "storage"
    ],
    "icons": {
        "128": "img/logo128.png"
    },
    "content_scripts": [
        {
            "run_at": "document_end",
            "matches": [
                "https://conferfly.com/*",
                "https://meet.google.com/*",
                "https://teams.microsoft.com/*",
                "https://*.zoom.us/*"
            ],
            "js": [
                "js/main.js",
                "js/injected.js"
            ],
            "css": [
                "css/main.css"
            ]
        }
    ],
    "web_accessible_resources": [
        "js/options.js",
        "js/main.js",
        "js/injected.js"
    ],
    "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
} 

thank you in advance


This is for conferfly extension

like image 343
Conferfly Avatar asked Aug 07 '20 19:08

Conferfly


People also ask

Is manifest V2 still supported?

Google's web browser will stop running Manifest V2 extensions, but there is an Enterprise policy which extends support by six months. In June 2023 finally, that Enterprise policy is removed and any version of Google Chrome won't run Manifest V2 extensions anymore.

Is manifest V2 deprecated?

(node:80082) ExtensionLoadWarning: Warnings loading extension at ./node_modules/electron-devtools-vendor/extensions/react-developer-tools: Manifest version 2 is deprecated, and support will be removed in 2023. See https://developer.chrome.com/blog/mv2-transition/ for more details.

What is browser action in manifest 3?

A browser action is a button that your extension adds to the browser's toolbar. The button has an icon, and may optionally have a popup whose content is specified using HTML, CSS, and JavaScript. This key is replaced by action in Manifest V3 extensions.

What is manifest in Chrome extension?

The manifest file uses JSON format to describe the important information about the extension. It contains fields that are required and recommended while others are optional depending on the extension you are building. name refers to the name of the extension and should be up to 45 characters.


1 Answers

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.

like image 118
newbiedev Avatar answered Sep 19 '22 09:09

newbiedev