()
| 269 | }; |
| 270 | |
| 271 | export const getLastFocusedTab = async () => { |
| 272 | const lastFocusedWindowIds = await getLastFocusedWindowIds(); |
| 273 | const windows = await chrome.windows.getAll({ populate: true }); |
| 274 | const lastFocusedWindow = windows |
| 275 | // sort windows by lastFocused |
| 276 | .sort( |
| 277 | (a, b) => |
| 278 | lastFocusedWindowIds.indexOf(a.id) - lastFocusedWindowIds.indexOf(b.id) |
| 279 | ) |
| 280 | // get windows that not popup extension |
| 281 | .filter((w) => w.type !== "popup" && w.tabs[0].url !== getPopupURL())?.[0]; |
| 282 | |
| 283 | if (!lastFocusedWindow) return null; |
| 284 | const tab = lastFocusedWindow.tabs.find( |
| 285 | (tab) => tab.active && tab.url !== getPopupURL() |
| 286 | ); |
| 287 | return tab; |
| 288 | }; |
| 289 | |
| 290 | export const getCurrentTab = async () => { |
| 291 | try { |
no test coverage detected