如何将清单版本2迁移到v3进行chrome扩展? [英] How to migrate manifest version 2 to v3 for chrome extension?

查看:618
本文介绍了如何将清单版本2迁移到v3进行chrome扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何将chrome扩展程序清单v2升级到v3

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

我检查了 https://developer.chrome.com/extensions/migrating_to_manifest_v3 但它没有不要谈论manifest.json

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'"
} 

先谢谢您

这是 conferfly 扩展名

推荐答案

我正在寻找相同的东西.多亏了用户wOxxOm的帮助,我才知道清单文件中要更改的内容.这是如何将 manifest.json 从v2迁移到v3的示例.

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.

第一件事是将 manifest_version 键从 2 更改为 3

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

//Manifest v2
"manifest_version": 2

//Manifest v3
"manifest_version": 3

按照清单迁移指南中的规定, pageAction browserAction API将统一在 action API下.这意味着您需要将 browser_action page_action 键更改为 action

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": {...}

背景页面和后台脚本已在清单v3中弃用.从服务人员处将其替换.这意味着清单文件的 background 部分需要以这种方式修改

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

要声明需要从Web访问的打包资源,需要以这种方式更改 web_accessible_resources

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": []
}]

v3中的内容安全策略是一个对象

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.

这篇关于如何将清单版本2迁移到v3进行chrome扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆