jackwener/OpenCLI · error · AuthRequiredError
Google session cookies are missing
Error message
Google session cookies are missing
What it means
verifyGmailIdentity first checks hasGoogleSession(page), which requires at least one of the SID, __Secure-1PSID, or SAPISID cookies for the Google domain. When none are present it throws AuthRequiredError('gmail', 'Google session cookies are missing'), meaning the browser has no authenticated Google/Gmail session.
Source
Thrown at clis/gmail/auth.js:13
import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';
import { GMAIL_HOST, GMAIL_ORIGIN, unwrapBrowserResult } from './utils.js';
async function hasGoogleSession(page) {
const cookies = await page.getCookies({ url: GMAIL_ORIGIN });
const names = new Set(cookies.map((cookie) => cookie.name));
return names.has('SID') || names.has('__Secure-1PSID') || names.has('SAPISID');
}
async function verifyGmailIdentity(page) {
if (!await hasGoogleSession(page)) {
throw new AuthRequiredError(GMAIL_HOST, 'Google session cookies are missing');
}
await page.goto(`${GMAIL_ORIGIN}/mail/u/0/#inbox`);
await page.sleep(2);
const result = unwrapBrowserResult(await page.evaluate(`(() => {
const account = Array.from(document.querySelectorAll('a[aria-label], button[aria-label]'))
.map((node) => String(node.getAttribute('aria-label') || '').trim())
.find((label) => /@/.test(label) && /(google account|google 帐号|google 账号)/i.test(label));
if (!account) {
const login = document.querySelector('a[href*="accounts.google.com/ServiceLogin"], input[type="email"]');
return login
? { kind: 'auth', detail: 'Gmail shows a Google sign-in surface' }
: { kind: 'shape', detail: 'Gmail account control was not found' };
}
const email = account.match(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/i)?.[0] || '';
const beforeEmail = email ? account.slice(0, account.indexOf(email)) : account;
const name = beforeEmail
.replace(/^.*?(?:google account|google 帐号|google 账号)\s*[::]?\s*/i, '')
.replace(/[,((]\s*$/, '')View on GitHub (pinned to 49907e53dc)
Solutions
- Log into Google/Gmail in the browser session, then re-run the command
- Point the automation at the persistent profile (user-data-dir) that already holds Google cookies
- Clear stale cookies and perform a fresh login if Google signed the session out globally
- Disable cookie-blocking extensions or enable cookies for google.com/gmail.com
Example fix
// before
const identity = await verifyGmailIdentity(page); // throws without cookies
// after
if (!await hasGoogleSession(page)) {
await performGoogleLogin(page, { account: 0 }); // interactive login
}
const identity = await verifyGmailIdentity(page); Defensive patterns
Strategy: validation
Validate before calling
const cookies = await page.cookies('https://mail.google.com');
const names = new Set(cookies.map(c => c.name));
if (!(['SID','__Secure-1PSID','SAPISID'].some(n => names.has(n)))) {
throw new Error('No Google session — log into Gmail first');
} Type guard
function hasGoogleSessionCookies(cookies) {
const names = new Set((cookies ?? []).map(c => c.name));
return names.has('SID') || names.has('__Secure-1PSID') || names.has('SAPISID');
} Try / catch
try {
const identity = await verifyGmailIdentity(page);
} catch (e) {
if (e instanceof AuthRequiredError && /cookies are missing/.test(e.message)) {
await interactiveGoogleLogin(page);
return verifyGmailIdentity(page);
}
throw e;
} Prevention
- Use a persistent profile that remains signed into Google
- Check SID/SAPISID cookies before each gmail command run
- Re-login proactively; Google can revoke sessions globally
- Disable cookie blockers for google.com
- Never share user-data-dir across unrelated automation jobs
When it happens
Trigger: Any gmail command's verify/poll path calls verifyGmailIdentity on a browser context whose Google cookie jar lacks SID, __Secure-1PSID, and SAPISID — i.e. never logged into Google in that profile, or the session was signed out/expired.
Common situations: Fresh or incognito browser profile; Google session expired (these cookies rotate/expire); user logged out of Google elsewhere causing global sign-out; cookie-blocking extensions or disabled cookies; wrong user-data-dir so cookies from the logged-in profile are not loaded.
Related errors
- Chaoxing session cookies missing
- Claude sessionKey cookie missing
- Claude session incomplete — ajs_user_id cookie missing
- ${result.detail}
- LinkedIn JSESSIONID cookie not found. Please sign in to Link
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/65e480a240b7865e.
Report an issue: GitHub.