MCPcopy Create free account
hub / github.com/garrytan/gstack / fetchAndRelayRefs

Function fetchAndRelayRefs

extension/background.js:159–185  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

157// ─── Refs Relay ─────────────────────────────────────────────────
158
159async function fetchAndRelayRefs() {
160 const base = getBaseUrl();
161 if (!base || !isConnected) return;
162
163 try {
164 const headers = {};
165 if (authToken) headers['Authorization'] = `Bearer ${authToken}`;
166 const resp = await fetch(`${base}/refs`, { signal: AbortSignal.timeout(3000), headers });
167 if (!resp.ok) {
168 console.warn(`[gstack bg] Refs endpoint returned ${resp.status}`);
169 return;
170 }
171 const data = await resp.json();
172
173 // Send to all tabs' content scripts
174 const tabs = await chrome.tabs.query({});
175 for (const tab of tabs) {
176 if (tab.id) {
177 chrome.tabs.sendMessage(tab.id, { type: 'refs', data }).catch(() => {
178 // Expected: tabs without content script
179 });
180 }
181 }
182 } catch (err) {
183 console.error('[gstack bg] Failed to fetch/relay refs:', err.message);
184 }
185}
186
187// ─── Inspector ──────────────────────────────────────────────────
188

Callers 1

background.jsFile · 0.85

Calls 2

getBaseUrlFunction · 0.85
fetchFunction · 0.50

Tested by

no test coverage detected