Chrome 清单 v3:runtime.lastError 指定 'func' 和 'files'?

Chrome manifest v3: runtime.lastError specify 'func' and 'files'?

我正在到处寻找解决方案,但我找不到关于此错误的任何信息。我正在尝试“更新”清单 v3 的 Chrome 扩展,但出现此错误:

Unchecked runtime.lastError: Exactly one of 'func' and 'files' must be specified

有人知道我该怎么做才能解决这个问题吗?这是我的 manifest.json:

{
    "manifest_version": 3,
    "name": "Extension_Name",
    "description": "Extension_Desc",
    "version": "5.0",
    "icons": {
        "16": "/images/image16.png",
        "48": "/images/image48.png",
        "128": "/images/image128.png"
    },
    "action": {
        "default_popup": "popup.html"
    },
    "permissions": [
        "storage",
        "activeTab",
        "scripting",
        "tabs"
    ],
    "host_permissions": [
        "https://example.com/*"
    ]
}

这是我的 popup.html,它在错误中被引用(但没有特定的行,只有 popup.html:0):

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="popup.css">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://example.com">
    <title>Extension Test</title>
</head>
<body>
    <h2>Ghost</h2>
    <form name ="form" id="login_form" action="#">
        <input type="text" id="mdp" placeholder="Password"/>
        <input type ="button" name="submit" value="Login" id="login"/>
    </form>
    
    <button id="logout">Logout</button>
    <script src="popup.js"></script>
</body>
</html>

我知道 manifest v3 不支持 unsafe-eval,但我稍后会处理这个错误。如果我删除不安全评估,另一个错误仍然存​​在,所以两者没有联系。 提前致谢!

最后通过在executeScript()函数中加入“files”解决了错误。在我拥有之前:

chrome.scripting.executeScript(
                {
                    target: {tabId: tab.id},
                    function: functionToExecute()
                })

找到的解决方案是:

chrome.scripting.executeScript(
                {
                    target: {tabId: tab.id},
                    files: ['popup.js'],
                    function: functionToExecute()
                })

再次感谢您的帮助!