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

Function openInCurrentTab

src/pkg/utils/utils.ts:114–144  ·  view source on GitHub ↗
(url: string, tabId?: number)

Source from the content-addressed store, hash-verified

112
113// 在当前页后打开一个新页面,如果指定tabId则在该tab后打开
114export async function openInCurrentTab(url: string, tabId?: number): Promise<chrome.tabs.Tab | undefined> {
115 const tab = await (tabId ? getTab(tabId) : getCurrentTab());
116 const createProperties: chrome.tabs.CreateProperties = { url };
117 if (tab) {
118 // 添加 openerTabId 有可能出现 Error "Tab opener must be in the same window as the updated tab."
119 if (tab.id! >= 0) {
120 // 如 Tab API 有提供 tab.id, 则指定 tab.id
121 createProperties.openerTabId = tab.id;
122 if (tab.windowId! >= 0) {
123 // 如 Tab API 有提供 tab.windowId, 则指定 tab.windowId
124 createProperties.windowId = tab.windowId;
125 }
126 }
127 createProperties.index = tab.index + 1;
128 }
129 // 先尝试以 openerTabId 和 windowId 打开
130 try {
131 return await chrome.tabs.create(createProperties);
132 } catch (e: any) {
133 console.error("Error opening tab:", e);
134 }
135 // 失败的话,删去 openerTabId 和 windowId ,再次尝试打开
136 delete createProperties.openerTabId;
137 delete createProperties.windowId;
138 try {
139 return await chrome.tabs.create(createProperties);
140 } catch (e: any) {
141 console.error("Retry opeing tab error:", e);
142 }
143 return undefined;
144}
145
146// 检查 connect 是否改变,是否能够静默更新
147// 用于订阅本身的更新检查和普通脚本的静默更新检查

Callers 11

onDropFunction · 0.90
index.tsxFile · 0.90
openImportWindowFunction · 0.90
AppFunction · 0.90
handleMenuClickFunction · 0.90
utils.test.tsFile · 0.90
confirmWindowMethod · 0.90
openInstallPageByUrlMethod · 0.90
openUpdatePageMethod · 0.90
openBatchUpdatePageMethod · 0.90
CAT_userConfigMethod · 0.90

Calls 4

getTabFunction · 0.85
getCurrentTabFunction · 0.85
errorMethod · 0.80
createMethod · 0.65

Tested by

no test coverage detected