I have a chrome extension in manifest v2 that I need to upgrade to v3.
It's an extension that raises an alarm at a set interval in whichever tab is currently open.
I had the following code in v2 -
background.js
var config = {
message: displaymessage,
button: "OK",
icon: "success",
};
chrome.scripting.executeScript(
null,
{
code: "var config = " + JSON.stringify(config),
},
function () {
chrome.scripting.executeScript(null, { file: "raisealert.js" }, () => {
console.log("Alarm triggered");
});
}
);
chrome.scripting.executeScript(
null,
{
code: "var config = " + JSON.stringify(config),
},
);
The config was then sent to the file raisealert.js which showed an alert to the user.
I am struggling with converting this to manifest v3. I am getting various errors. The latest one is
or in event handler: TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator))
at showpopup()
with the code -
background_service_worker.js
let [tab] = chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: () => {
var config = JSON.parse("${JSON.stringify(config)}");
return config;
},
});
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["raisealert.js"],
});
console.log("Alarm triggered");
How can I fix this? Essentially, all I want to do is to be able to execute the script - raisealert.js with the config json.