({
url,
func,
args = [],
world = "MAIN",
waitUntilLoadEnd = true,
focusAfterRunScript = true,
closeAfterRunScript = false,
focusImmediately = false,
})
| 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 |
| 449 | export 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 | |
| 486 | export function attachDebugger(tab) { |
| 487 | return chrome.debugger.attach({ tabId: tab.id }, "1.2"); |
no test coverage detected