【问题标题】:ManifestV3: "invalid value for web_accessible_resources" or "resources must be listed" errorsManifestV3:“web_accessible_resources 的值无效”或“必须列出资源”错误
【发布时间】:2021-04-22 12:39:23
【问题描述】:

这是我第一次尝试编写 Chrome 扩展程序。我将 "web_accessible_resources": ["images/icon.png"] 添加到 ma​​nifest.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"]
}

【问题讨论】:

    标签: json google-chrome-extension


    【解决方案1】:

    Manifest V3 中web_accessible_resources 的语法已更改:

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

    matches必须指定自 Chrome 89 以来公开这些资源的位置。

    【讨论】:

    • 您可能需要指定一些匹配项才能使其正常工作,例如"matches": ["http://*/*", "https://*/*"] 表示与 MV2 中相同的行为,或更具体的 URL 集
    • 绝对是典型的谷歌。截至目前,developer.chrome.com/docs/extensions/mv3/intro/mv3-migration 仍然提到“matches、extension_ids 和 use_dynamic_url 键尚不可用。未来版本将支持这些属性。”
    猜你喜欢
    • 2022-12-02
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-13
    • 2022-10-17
    • 1970-01-01
    • 2019-03-11
    相关资源
    最近更新 更多