I'm searching for a solution everywhere and I can't find nothing about this error. I'm trying to "update" a Chrome extension to manifest v3 and I get this error:
Unchecked runtime.lastError: Exactly one of 'func' and 'files' must be specified
Does somebody have an idea on what can I do to solve this? Here is my 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/*"
]
}
And here is my popup.html, that is referenced in the error (but without a specific line, only 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>
I know that unsafe-eval is not supported in manifest v3, but I will deal with this error later. If I delete unsafe-eval, the other error remains, so the two are not linked. Thank you in advance!
CodePudding user response:
Finally, the error is solved by adding "files" in the executeScript() function. Before I had:
chrome.scripting.executeScript(
{
target: {tabId: tab.id},
function: functionToExecute()
})
The solution found is:
chrome.scripting.executeScript(
{
target: {tabId: tab.id},
files: ['popup.js'],
function: functionToExecute()
})
Thanks again for the help!