MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / getLastFocusedTab

Function getLastFocusedTab

scripts/helpers/utils.js:271–288  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

269};
270
271export 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
290export const getCurrentTab = async () => {
291 try {

Callers 1

getCurrentTabFunction · 0.85

Calls 4

getLastFocusedWindowIdsFunction · 0.85
getPopupURLFunction · 0.85
filterMethod · 0.80
sortMethod · 0.80

Tested by

no test coverage detected