({
files = null,
func = null,
args = null,
tabId = null,
frameIds = [0],
allFrames = false,
world = 'ISOLATED',
injectImmediately = true,
unwrapResults = true,
code = ''
})
| 52 | } |
| 53 | |
| 54 | async function executeScript({ |
| 55 | files = null, |
| 56 | func = null, |
| 57 | args = null, |
| 58 | tabId = null, |
| 59 | frameIds = [0], |
| 60 | allFrames = false, |
| 61 | world = 'ISOLATED', |
| 62 | injectImmediately = true, |
| 63 | unwrapResults = true, |
| 64 | |
| 65 | code = '' |
| 66 | }) { |
| 67 | if (mv3 || (targetEnv === 'firefox' && (await getBrowserVersion()) >= 128)) { |
| 68 | const params = {target: {tabId}, world}; |
| 69 | |
| 70 | // Safari 17: allFrames and frameIds cannot both be specified, |
| 71 | // fixed in Safari 18. |
| 72 | if (allFrames) { |
| 73 | params.target.allFrames = true; |
| 74 | } else { |
| 75 | params.target.frameIds = frameIds; |
| 76 | } |
| 77 | |
| 78 | if (files) { |
| 79 | params.files = files; |
| 80 | } else { |
| 81 | params.func = func; |
| 82 | |
| 83 | if (args) { |
| 84 | params.args = args; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if (targetEnv !== 'safari') { |
| 89 | params.injectImmediately = injectImmediately; |
| 90 | } |
| 91 | |
| 92 | const results = await browser.scripting.executeScript(params); |
| 93 | |
| 94 | if (unwrapResults) { |
| 95 | return results.map(item => item?.result); |
| 96 | } else { |
| 97 | return results; |
| 98 | } |
| 99 | } else { |
| 100 | const params = {frameId: frameIds[0]}; |
| 101 | |
| 102 | if (files) { |
| 103 | params.file = files[0]; |
| 104 | } else { |
| 105 | params.code = code; |
| 106 | } |
| 107 | |
| 108 | if (injectImmediately) { |
| 109 | params.runAt = 'document_start'; |
| 110 | } |
| 111 |
no test coverage detected
searching dependent graphs…