MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / getCurrentTab

Function getCurrentTab

src/pkg/utils/utils.ts:101–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

99
100// https://developer.chrome.com/docs/extensions/reference/api/tabs?hl=en#get_the_current_tab
101export 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
109export async function getTab(tabId: number) {
110 return await chrome.tabs.get(tabId).catch(() => undefined);

Callers 5

queryTabInfoFunction · 0.90
initManagerMethod · 0.90
doBadgeAndMenuUpdateMethod · 0.90
GM_openInTabMethod · 0.90
openInCurrentTabFunction · 0.85

Calls 1

queryMethod · 0.80

Tested by

no test coverage detected