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

这是我第一次尝试编写 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"]
}

回答

web_accessible_resourcesManifest V3 中的语法已更改:

"web_accessible_resources": [{ 
  "resources": ["/images/icon.png"],
  "matches": ["<all_urls>"]
}]

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

  • You probably need to specify some matches to get it to work, e.g. `"matches": ["http://*/*", "https://*/*"]` for the same behavior as in MV2, or a more specific set of URLs

以上是ManifestV3:“web_accessible_resources的值无效”或“必须列出资源”错误的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>