()
| 99 | |
| 100 | // https://developer.chrome.com/docs/extensions/reference/api/tabs?hl=en#get_the_current_tab |
| 101 | export async function getCurrentTab(): Promise<chrome.tabs.Tab | undefined> { |
| 102 | // `tab` will either be a `tabs.Tab` instance or `undefined`. |
| 103 | // 不要使用 windowType: "normal" ,否则在使用应用窗口时获取不到 tab 了 |
| 104 | const [tab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true }); |
| 105 | if (tab?.discarded) return undefined; |
| 106 | return tab; |
| 107 | } |
| 108 | |
| 109 | export async function getTab(tabId: number) { |
| 110 | return await chrome.tabs.get(tabId).catch(() => undefined); |
no test coverage detected