(READ ONLY) Margin is an open annotation layer for the internet. Powered by the AT Protocol. margin.at
extension web atproto comments
98
fork

Configure Feed

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

Support Firefox Container Tabs #1

open opened by joeinn.es targeting main from joeinn.es/margin: joe/broken-ff-extension-signin

Summary#

  • browser.cookies.get without a storeId reads from the background context's default cookie store, so a margin_session cookie set inside a Firefox container tab was invisible to the extension and the popup stayed on the Sign In screen.
  • getSessionCookie() now tries the active tab's cookieStoreId first, then the default store, then iterates cookies.getAllCookieStores() for the first match.

Test plan#

  • In Firefox, log out of margin.at, then sign in to margin.at inside a container tab. Open the extension popup and confirm it shows the signed-in state.
  • In a non-container tab, sign in and confirm the popup still works (regression check).

AI use disclosure#

AI was used to help diagnose the issue and propose the fix. The code has been manually reviewed and tested (there were no automated tests, none have been added).

Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:me4kozmcrc74z2wgkvqvkbfd/sh.tangled.repo.pull/3mkkavxrrjp22
+38 -5
Diff #0
+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;

History

1 round 0 comments
sign up or login to add to the discussion
joeinn.es submitted #0
1 commit
expand
fix extension sign-in inside Firefox container tabs
merge conflicts detected
expand
  • extension/src/utils/api.ts:8
expand 0 comments