ManifestV3:“web_accessible_resources 的值无效”或“必须列出资源”错误

cha*_*han 5 json google-chrome-extension

这是我第一次尝试编写 Chrome 扩展程序。我添加"web_accessible_resources": ["images/icon.png"]manifest.json是因为我想从内容脚本访问图像。添加此行后,我收到错误“'web_accessible_resources[0]' 的值无效。无法加载清单。” 我已经检查以确保文件路径是正确的,还有什么地方是我错的?任何帮助表示赞赏。

{
    "name": "Bookmark Checker",
    "version": "1.0",
    "manifest_version": 3,
    "permissions": [
        "bookmarks",
        "activeTab"
    ],
    "background": {
        "service_worker": "background.js"
    },
    "content_scripts": [
        {
            "matches":["https://www.google.com/search?*"],
            "js": ["content/content.js"]
        }
    ],
    ...
    "web_accessible_resources": ["images/icon.png"]
}
Run Code Online (Sandbox Code Playgroud)

cha*_*han 18

web_accessible_resourcesManifest V3 中的语法已更改:

"web_accessible_resources": [{ 
  "resources": ["/images/icon.png"],
  "matches": ["<all_urls>"]
}]
Run Code Online (Sandbox Code Playgroud)

自 Chrome 89 起,matches密钥必须指定在何处公开这些资源。

  • 您可能需要指定一些匹配才能使其正常工作,例如 `"matches": ["http://*/*", "https://*/*"]` 与 MV2 中的行为相同,或者一组更具体的 URL (4认同)
  • 绝对典型的谷歌。截至目前 https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/ 仍然提到“The matches、extension_ids 和 use_dynamic_url 键尚不可用。对这些属性的支持将会到来”未来的版本。” (2认同)