MCPcopy Create free account
hub / github.com/anilkumarum/mark-clipper / injectScript

Function injectScript

background/util.js:62–77  ·  view source on GitHub ↗
(...scripts)

Source from the content-addressed store, hash-verified

60
61/**@param {string[]} scripts*/
62export async function injectScript(...scripts) {
63 const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
64 try {
65 await chrome.scripting.executeScript({ target: { tabId: tab.id }, files: scripts });
66 } catch (error) {
67 const errMsg =
68 "Cannot access contents of the page. Extension manifest must request permission to access the respective host.";
69 if (error.message === errMsg) {
70 const { id } = await chrome.tabs.create({ url: "/permission/index.html", index: tab.index + 1 });
71 await new Promise((r) => setTimeout(r, 1000));
72 const granted = await chrome.tabs.sendMessage(id, "requestHostPermission");
73 if (granted) await chrome.scripting.executeScript({ target: { tabId: tab.id }, files: scripts });
74 }
75 console.info(error);
76 }
77}
78
79/**@param {(...args: any[]) => any} func*/
80export async function injectFuncScript(func, ...args) {

Callers 1

background.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected