【问题标题】:How to specify an external script in manifest version-3 for Chrome Extension如何在清单版本 3 中为 Chrome 扩展程序指定外部脚本
【发布时间】:2023-01-17 22:36:09
【问题描述】:

这是我的清单文件 -

    {
    "manifest_version": 3,
    "name": "Title",
    "version": "1.0",
    "description": "Description",
    "action": {
        "default_title": "Title",
        "default_popup": "popup.html"
    },
    "content_security_policy": {
        "script-src": [
            "'self'",
            "https://use.fontawesome.com/9cd1c736ac.js"
        ],
        "object-src": "self"
    },
    "web_accessible_resources": [
        {
            "resources": [
                "botScript.js"
            ],
            "matches": [],
            "extension_ids": []
        }
    ],
    "icons": {
        "16": "icons/icon16.png",
        "32": "icons/icon32.png",
        "48": "icons/icon48.png",
        "128": "icons/icon128.png"
    }
}

以下是清单版本 2,不适用于版本 3:

"content_security_policy": "script-src 'self' https://example.com ; object-src 'self'",

我也尝试了以下变化 -

    "content_security_policy": {
        "script-src": "'self' https://use.fontawesome.com/9cd1c736ac.js",
        "object-src": "self"
    }

    "content_security_policy": {
        "script-src": "self",
        "script-src-elem": "https://use.fontawesome.com/9cd1c736ac.js",
        "object-src": "self"
    },

documentation

Manifest V3 does not allow remote URLs in script-src of extension_pages.

那么,这是否意味着我们根本不能在 V3 中使用任何外部脚本?

另外,我收到以下错误:

Refused to load the script 'https://use.fontawesome.com/9cd1c736ac.js' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

【问题讨论】:

  • 您不能在 Manifest v3 中使用外部脚本。下载它们并将它们包含在您的扩展包中。

标签: json google-chrome-extension chrome-extension-manifest-v3


【解决方案1】:

不允许在 Manifest V3 Chrome 扩展中引用外部 JavaScript。如果您将其发布到 Chrome 网上应用店,该团队将拒绝该更新。

在 Manifest V3 中,您的所有扩展逻辑都必须包含在 延期。您不能再加载和执行远程托管的文件。

来源:https://developer.chrome.com/docs/extensions/mv3/mv3-migration/#:~:text=In%20Manifest%20V3%2C%20all%20of%20your%20extension%27s%20logic%20must%20be%20included%20in%20the%20extension.%20You%20can%20no%20longer%20load%20and%20execute%20a%20remotely%20hosted%20file.

【讨论】:

    猜你喜欢
    • 2021-10-16
    • 1970-01-01
    • 2012-08-02
    • 2012-08-02
    • 2012-09-03
    • 2021-05-04
    • 2011-10-03
    • 1970-01-01
    相关资源
    最近更新 更多