MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / runScriptInTab

Function runScriptInTab

scripts/helpers/utils.js:386–406  ·  view source on GitHub ↗
(config = {})

Source from the content-addressed store, hash-verified

384};
385
386export const runScriptInTab = async (config = {}) => {
387 return new Promise((resolve, reject) => {
388 chrome.scripting.executeScript(
389 mergeObject(
390 {
391 world: "MAIN",
392 injectImmediately: true,
393 },
394 config
395 ),
396 (injectionResults) => {
397 if (chrome.runtime.lastError) {
398 console.error(chrome.runtime.lastError);
399 reject(chrome.runtime.lastError);
400 }
401 // https://developer.chrome.com/docs/extensions/reference/scripting/#handling-results
402 else resolve(injectionResults?.find?.((_) => _.result)?.result);
403 }
404 );
405 });
406};
407
408export const runScriptFile = (config = {}) => {
409 return new Promise((resolve, reject) => {

Callers 5

runScriptInCurrentTabFunction · 0.70
openWebAndRunScriptFunction · 0.70
setEnableForAllTabFunction · 0.50
web_timer.jsFile · 0.50

Calls 2

errorMethod · 0.80
mergeObjectFunction · 0.70

Tested by

no test coverage detected