I'm currently working on a Chrome extension and I want to inject code into the page. However, I'm unsure how to achieve this without specifying fun: any
and arg: any
.
type funs = typeof getPageInfo | typeof setPercen;
async function injectScriptToPage<K extends funs>(fun: K, arg: Parameters<K>): Promise<dataPageU> {
if (actTab.id === undefined) {
console.log("vacio tab id");
return;
}
const pr = await chrome.scripting.executeScript({
target: {tabId: actTab.id},
// files: ["./dist/injectScript.js"],
func: fun, // <- Error here
args: arg,
});
const x = pr?.[0]?.result as dataPageU;
if (x === undefined) {
console.log("vacio result");
return;
}
if (!("titulo" in x) && !("currentTime" in x)) console.log("Err no es ni refresh ni once");
return x;
}
Functions:
export function setPercen(l: StateVideoI[]): void
export function getPageInfo(once: boolean, YoT: "Y" | "T"): dataPage
The current code functions with 'any', however, my goal is to utilize types if possible.