{"record":{"id":"dd1b00e924fa5c9e","repo":"jackwener/OpenCLI","slug":"chatgpt-requires-a-logged-in-browser-session","errorCode":null,"errorMessage":"ChatGPT requires a logged-in browser session.","messagePattern":"ChatGPT requires a logged-in browser session\\.","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/chatgpt/utils.js","lineNumber":365,"sourceCode":"            const label = ((node.innerText || node.textContent || '') + ' ' + (node.getAttribute('aria-label') || '')).trim().toLowerCase();\n            return isVisible(node) && /^(log in|login|sign up|sign in)$/.test(label);\n        });\n        const userMenu = document.querySelector('[data-testid=\"profile-button\"], [aria-label*=\"Profile\"], [aria-label*=\"Account\"], button[id*=\"headlessui-menu-button\"]');\n        const hasLoginGate = !!loginLink || /log in to chatgpt|sign up to chatgpt|welcome to chatgpt/i.test(text);\n        return {\n            url: window.location.href,\n            title: document.title,\n            hasComposer,\n            isLoggedIn: hasComposer || !!userMenu || !hasLoginGate,\n            hasLoginGate,\n        };\n    })()`)), 'chatgpt page state');\n}\n\nexport async function ensureChatGPTLogin(page, message = 'ChatGPT requires a logged-in browser session.') {\n    const state = await getPageState(page);\n    if (!state.isLoggedIn || state.hasLoginGate) {\n        throw new AuthRequiredError(CHATGPT_DOMAIN, message);\n    }\n    return state;\n}\n\nexport async function ensureChatGPTComposer(page, message = 'ChatGPT composer is not available on the current page.') {\n    const state = await ensureChatGPTLogin(page, message);\n    if (!state.hasComposer) {\n        throw new CommandExecutionError(message);\n    }\n    return state;\n}\n\nfunction requireKnownChatGPTModel(model) {\n    const key = String(model ?? '').trim().toLowerCase();\n    const targetKey = CHATGPT_MODEL_ALIASES[key] || key;\n    const option = CHATGPT_MODEL_TARGETS[targetKey];\n    if (!option) {\n        throw new ArgumentError(","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chatgpt/utils.js#L347-L383","documentation":"ensureChatGPTLogin reads the page state and throws AuthRequiredError (domain chatgpt.com) when state.isLoggedIn is false or a login gate is present. All chatgpt read/detail/history/project commands funnel through it, so any unauthenticated browser session surfaces this message (or the command-specific override).","triggerScenarios":"Running any chatgpt command while the automation browser has no logged-in chatgpt.com session, after the session cookie expired, in a fresh browser profile, or when the page shows the login wall.","commonSituations":"CI environments with a brand-new browser profile, clearing cookies manually, ChatGPT logging the session out, or pointing the CLI at a profile never used to log in.","solutions":["Open the automation browser profile and log into chatgpt.com interactively once","Reuse a persistent browser profile so the session cookie survives restarts","Re-run the command after re-authenticating; the session check will pass","Catch AuthRequiredError in wrappers and prompt the user to log in instead of retrying blindly"],"exampleFix":"// before\nconst state = await readCommand(...); // fresh profile, not logged in\n// after\nawait launch({ persistent: true, userDataDir: './chrome-profile' });\n// log into chatgpt.com once in that profile, then\nconst state = await readCommand(...);","handlingStrategy":"try-catch","validationCode":"const state = await getPageState(page).catch(() => null);\nconst loggedIn = state?.isLoggedIn && !state?.hasLoginGate;","typeGuard":"function isLoggedInState(s) { return Boolean(s && s.isLoggedIn === true && s.hasLoginGate === false); }","tryCatchPattern":"try { await ensureChatGPTLogin(page); } catch (e) { if (e instanceof AuthRequiredError) { console.error('Log into chatgpt.com in the automation browser profile, then retry.'); process.exitCode = 3; } else throw e; }","preventionTips":["Use a persistent userDataDir profile and log in once","Check page state (isLoggedIn) before batch operations","Do not clear cookies of the automation profile","In CI, provision a profile with a stored session or run a login step first"],"tags":["authentication","browser-session","login-gate"],"backgroundTag":"login-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}