diff --git a/src/lib/cookies.ts b/src/lib/cookies.ts index 6a88107..88e6de3 100644 --- a/src/lib/cookies.ts +++ b/src/lib/cookies.ts @@ -34,19 +34,30 @@ function getChromeCookiesPath(profile?: string): string { return join(home, 'Library', 'Application Support', 'Google', 'Chrome', profileDir, 'Cookies'); } -function getFirefoxCookiesPath(profile?: string): string | null { +function getFirefoxProfilesRoot(): string | null { const home = process.env.HOME || ''; - const profilesRoot = join(home, 'Library', 'Application Support', 'Firefox', 'Profiles'); - if (!existsSync(profilesRoot)) return null; + if (process.platform === 'darwin') { + return join(home, 'Library', 'Application Support', 'Firefox', 'Profiles'); + } + if (process.platform === 'linux') { + return join(home, '.mozilla', 'firefox'); + } + if (process.platform === 'win32') { + const appData = process.env.APPDATA; + if (!appData) return null; + return join(appData, 'Mozilla', 'Firefox', 'Profiles'); + } + return null; +} +function pickFirefoxProfile(profilesRoot: string, profile?: string): string | null { if (profile) { const candidate = join(profilesRoot, profile, 'cookies.sqlite'); return existsSync(candidate) ? candidate : null; } - // Pick the default-release profile if present, otherwise first profile dir containing cookies.sqlite const entries = readdirSync(profilesRoot, { withFileTypes: true }); - const defaultRelease = entries.find((entry) => entry.isDirectory() && entry.name.endsWith('.default-release')); + const defaultRelease = entries.find((entry) => entry.isDirectory() && entry.name.includes('default-release')); const targetDir = defaultRelease?.name ?? entries.find((e) => e.isDirectory())?.name; if (!targetDir) return null; @@ -54,6 +65,12 @@ function getFirefoxCookiesPath(profile?: string): string | null { return existsSync(candidate) ? candidate : null; } +function getFirefoxCookiesPath(profile?: string): string | null { + const profilesRoot = getFirefoxProfilesRoot(); + if (!profilesRoot || !existsSync(profilesRoot)) return null; + return pickFirefoxProfile(profilesRoot, profile); +} + /** * Decrypt Chrome cookie value using macOS keychain * Chrome encrypts cookies with a key stored in the keychain @@ -260,7 +277,9 @@ export async function extractCookiesFromFirefox(profile?: string): Promise