MCPcopy Create free account
hub / github.com/TheSmallHanCat/flow2api / waitForTabReady

Function waitForTabReady

extension/background.js:44–72  ·  view source on GitHub ↗
(tabId, timeoutMs = 12000)

Source from the content-addressed store, hash-verified

42}
43
44function waitForTabReady(tabId, timeoutMs = 12000) {
45 return new Promise((resolve) => {
46 let settled = false;
47 const finish = () => {
48 if (settled) return;
49 settled = true;
50 chrome.tabs.onUpdated.removeListener(onUpdated);
51 clearTimeout(timer);
52 resolve();
53 };
54 const onUpdated = (updatedTabId, changeInfo) => {
55 if (updatedTabId === tabId && changeInfo.status === "complete") {
56 finish();
57 }
58 };
59 const timer = setTimeout(finish, timeoutMs);
60
61 chrome.tabs.onUpdated.addListener(onUpdated);
62 chrome.tabs.get(tabId, (tab) => {
63 if (chrome.runtime.lastError) {
64 finish();
65 return;
66 }
67 if (tab && tab.status === "complete") {
68 finish();
69 }
70 });
71 });
72}
73
74async function connectWS() {
75 if (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING)) return;

Callers 1

handleGetTokenFunction · 0.85

Calls 1

finishFunction · 0.85

Tested by

no test coverage detected