forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.ts
More file actions
22 lines (20 loc) · 663 Bytes
/
script.ts
File metadata and controls
22 lines (20 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { IS_MV3 } from "@util/constant/environment"
import { handleError } from "./common"
export async function executeScript(tabId: number, files: string[]): Promise<void> {
if (IS_MV3) {
try {
await chrome.scripting.executeScript({ target: { tabId }, files })
} catch {
}
} else {
await Promise.all(files.map(file => executeScriptMv2(tabId, file)))
}
}
function executeScriptMv2(tabId: number, file: string): Promise<void> {
return new Promise(resolve => {
chrome.tabs.executeScript(tabId, { file }, () => {
handleError('executeScript')
resolve()
})
})
}