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

Function openWebAndRunScript

scripts/helpers/utils.js:449–484  ·  view source on GitHub ↗
({
  url,
  func,
  args = [],
  world = "MAIN",
  waitUntilLoadEnd = true,
  focusAfterRunScript = true,
  closeAfterRunScript = false,
  focusImmediately = false,
})

Source from the content-addressed store, hash-verified

447// WARNING: should be run in backgound script
448// If use this in popup script, when tab is focus, popup page will be closed => script not finish
449export async function openWebAndRunScript({
450 url,
451 func,
452 args = [],
453 world = "MAIN",
454 waitUntilLoadEnd = true,
455 focusAfterRunScript = true,
456 closeAfterRunScript = false,
457 focusImmediately = false,
458}) {
459 let win = await chrome.windows.create({
460 url,
461 type: "popup",
462 width: 500,
463 height: 500,
464 });
465 // let tab = await chrome.tabs.create({ active: focusImmediately, url: url });
466 let tab = win.tabs[0];
467 if (focusImmediately) {
468 await focusToTab(tab);
469 await chrome.windows.update(win.id, { focused: true });
470 }
471 if (waitUntilLoadEnd) await waitForTabToLoad(tab.id);
472 let res = await runScriptInTab({
473 func,
474 target: { tabId: tab.id },
475 args,
476 world,
477 });
478 if (closeAfterRunScript) {
479 closeTab(tab);
480 } else if (focusAfterRunScript) {
481 focusToTab(tab);
482 }
483 return res;
484}
485
486export function attachDebugger(tab) {
487 return chrome.debugger.attach({ tabId: tab.id }, "1.2");

Callers 3

studocu_downs.jsFile · 0.85
test.jsFile · 0.85

Calls 5

focusToTabFunction · 0.85
closeTabFunction · 0.85
updateMethod · 0.80
waitForTabToLoadFunction · 0.70
runScriptInTabFunction · 0.70

Tested by

no test coverage detected