I am trying to improve the script injection in chrome extension. As per the previous implementation written using manifest version 2, a function string was coming in the response of an API call and then the function string is again wrapped inside another function string and then passed to the executeScript function to do it's task.
For Ex: Let say API call send the below function string in the response:
function() {perform_login(doc)};
Now, it is again processed and converted to the below function string
const script = "function() {" + execTag + "\n perform_login(document); }";
Where execTag is the variable holding the value of API response function string. And the inject function is called as below
chrome.tabs.executeScript(tabId, {code, run_at: "document_end"}, executeCallback);
where
code = "(" + someWrapperFn + ")" + "(" + script + ")";
and executeCallback is some other function that will execute during the process.
Now, as per the manifest version 3 executeScript docs - The format of executeScript is changed and now there is no code object.
How can I change the current implementation so that it injects scripts properly? How can I convert the function strings to normal functions?