converting a Chrome extension from V2 to V3 - I've added the line:
"content_security_policy": {
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src
'self' 'wasm-unsafe-eval'"
},
When running the extension, I get the error:
Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval'
is not an allowed source of script in the following Content Security Policy directive:
"script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules'
Below is my manifest file:
{
"name": "Fill DTX 24x7 team",
"version": "1.1",
"content_security_policy": {
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src
'self' 'wasm-unsafe-eval'"
},
"description": "Enters hours, codes and tasks into DTX!",
"permissions": [ "activeTab", "declarativeContent", "storage", "scripting" ],
"options_page": "options.html",
"background": {
"service_worker": "background.js",
"type": "module"
},
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
}
},
"icons": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
},
"manifest_version": 3
}
This is the code in my popup.js file, that defines the code to run (just an alert('hi') for the sake of troubleshooting:
cde = "alert('hi')";
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs)
{
var tab = tabs[0];
if (tab) {
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: (cde) => {
console.log(cde);
eval(cde);
},
args: [cde]
}).then(() => {
console.log('Script executed successfully.');
alert(cde);
alert('Script executed successfully.');
}).catch((error) => {
console.error(error);
alert(error);
});
} else {
console.error('No active tab found.');
alert("no active tab found");
}
});
Any ideas what I may have missed?
Thanks, Mark