{"record":{"id":"5ec47b874d5ca4c9","repo":"jackwener/OpenCLI","slug":"google-session-cookies-sid-sapisid-missing","errorCode":null,"errorMessage":"Google session cookies (SID / SAPISID) missing","messagePattern":"Google session cookies \\(SID / SAPISID\\) missing","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/gemini/auth.js","lineNumber":12,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasGoogleSessionCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://gemini.google.com' });\n  const names = new Set(cookies.map(c => c.name));\n  return names.has('SID') || names.has('SAPISID') || names.has('__Secure-1PSID');\n}\n\nasync function verifyGeminiIdentity(page) {\n  if (!await hasGoogleSessionCookie(page)) {\n    throw new AuthRequiredError('gemini.google.com', 'Google session cookies (SID / SAPISID) missing');\n  }\n  await page.goto('https://gemini.google.com/app');\n  await page.wait(3);\n  const probe = await page.evaluate(`\n    (() => {\n      const a = document.querySelector('a[aria-label^=\"Google Account:\"]');\n      if (!a) {\n        return { kind: 'auth', detail: 'Gemini account link missing — not signed into Google' };\n      }\n      const label = a.getAttribute('aria-label') || '';\n      const m = label.match(/Google Account:\\\\s*([^(]+?)\\\\s*\\\\(([^)]+)\\\\)/);\n      if (!m) {\n        return { kind: 'auth', detail: 'Gemini aria-label unparseable: ' + label };\n      }\n      return { ok: true, name: m[1].trim() };\n    })()\n  `);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('gemini.google.com', probe.detail);","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gemini/auth.js#L1-L30","documentation":"An AuthRequiredError thrown by verifyGeminiIdentity when the browser has none of Google's session cookies (SID, SAPISID, or __Secure-1PSID). Without these cookies gemini.google.com requests are unauthenticated, so the library short-circuits and signals login is required.","triggerScenarios":"`hasGoogleSessionCookie(page)` returns false — the automation browser profile has no SID/SAPISID/__Secure-1PSID cookies when ask/auth commands run.","commonSituations":"Never logged in to Google in the automation browser; cookies expired or cleared; using a fresh/incognito profile; corporate proxy blocking accounts.google.com; logged out remotely.","solutions":["Run `opencli gemini login` to complete Google sign-in in the automation browser","Re-run the command with a persistent browser profile that retains Google cookies","Log in to gemini.google.com manually in the automation browser profile","Check that no proxy/extensions are stripping Google cookies"],"exampleFix":"// before\nopencli gemini ask \"hi\"\n// after\nopencli gemini login   # establishes SID/SAPISID cookies\nopencli gemini ask \"hi\"","handlingStrategy":"validation","validationCode":"const cookies = await getCookies('https://gemini.google.com');\nconst names = new Set(cookies.map(c => c.name));\nif (!(names.has('SID') || names.has('SAPISID') || names.has('__Secure-1PSID'))) {\n  await runLoginFlow(); // opencli gemini login\n}","typeGuard":"function hasGoogleSession(cookies) {\n  const n = new Set(cookies.map(c => c.name));\n  return n.has('SID') || n.has('SAPISID') || n.has('__Secure-1PSID');\n}","tryCatchPattern":"try {\n  await geminiAsk(prompt);\n} catch (e) {\n  if (e.name === 'AuthRequiredError' && /cookies/.test(e.message)) {\n    await geminiLogin();      // interactive sign-in\n    await geminiAsk(prompt);  // retry\n  } else throw e;\n}","preventionTips":["Run `opencli gemini login` before automation sessions","Use a persistent browser profile so cookies survive restarts","Check auth status with the site's whoami/status command first","Avoid incognito/ephemeral profiles for Google automation"],"tags":["auth","gemini","cookies"],"backgroundTag":"auth-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}