(READ ONLY) Margin is an open annotation layer for the internet. Powered by the AT Protocol.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix extension sign-in inside Firefox container tabs

`browser.cookies.get` without a `storeId` reads from the background
context's default store, so a `margin_session` cookie set inside a
container tab was invisible to the extension and the popup stayed on
the Sign In screen. Try the active tab's cookie store first, then the
default, then iterate `getAllCookieStores()` for first-match.

+38 -5
+38 -5
extension/src/utils/api.ts
··· 8 8 async function getSessionCookie(): Promise<string | null> { 9 9 try { 10 10 const apiUrl = await getApiUrl(); 11 - const cookie = await browser.cookies.get({ 12 - url: apiUrl, 13 - name: 'margin_session', 14 - }); 15 - return cookie?.value || null; 11 + 12 + const readFrom = async (storeId?: string) => { 13 + const cookie = await browser.cookies.get({ 14 + url: apiUrl, 15 + name: 'margin_session', 16 + ...(storeId ? { storeId } : {}), 17 + }); 18 + return cookie?.value || null; 19 + }; 20 + 21 + let activeStoreId: string | undefined; 22 + try { 23 + const [activeTab] = await browser.tabs.query({ active: true, currentWindow: true }); 24 + activeStoreId = (activeTab as { cookieStoreId?: string } | undefined)?.cookieStoreId; 25 + } catch { 26 + // ignore: tabs.query can fail in some contexts 27 + } 28 + 29 + if (activeStoreId) { 30 + const value = await readFrom(activeStoreId); 31 + if (value) return value; 32 + } 33 + 34 + const defaultValue = await readFrom(); 35 + if (defaultValue) return defaultValue; 36 + 37 + try { 38 + const stores = await browser.cookies.getAllCookieStores(); 39 + for (const store of stores) { 40 + if (store.id === activeStoreId) continue; 41 + const value = await readFrom(store.id); 42 + if (value) return value; 43 + } 44 + } catch { 45 + // ignore: getAllCookieStores may not be supported everywhere 46 + } 47 + 48 + return null; 16 49 } catch (error) { 17 50 console.error('Get cookie error:', error); 18 51 return null;