{"record":{"id":"34ed8656b149ad84","repo":"jackwener/OpenCLI","slug":"not-logged-in-sapisid-cookie-missing-34ed86","errorCode":null,"errorMessage":"Not logged in (SAPISID cookie missing)","messagePattern":"Not logged in \\(SAPISID cookie missing\\)","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"critical","filePath":"clis/youtube/unlike.js","lineNumber":25,"sourceCode":"\ncli({\n    site: 'youtube',\n    name: 'unlike',\n    access: 'write',\n    description: 'Remove like from a YouTube video',\n    domain: 'www.youtube.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        { name: 'url', required: true, positional: true, help: 'YouTube video URL or video ID' },\n    ],\n    columns: ['status', 'message'],\n    func: async (page, kwargs) => {\n        const videoId = parseVideoId(String(kwargs.url));\n        await prepareYoutubeApiPage(page);\n        // Read SAPISID directly from the cookie store via CDP — zero document.cookie round-trip\n        const sapisid = await readYoutubeSapisid(page);\n        if (!sapisid)\n            throw new AuthRequiredError('www.youtube.com', 'Not logged in (SAPISID cookie missing)');\n        const result = await page.evaluate(`\n      (async () => {\n        ${SAPISID_HASH_FN}\n\n        const cfg = window.ytcfg?.data_ || {};\n        const apiKey = cfg.INNERTUBE_API_KEY;\n        const context = cfg.INNERTUBE_CONTEXT;\n        if (!apiKey || !context) return { error: 'config', message: 'YouTube config not found' };\n\n        const authHash = await getSapisidHash(${JSON.stringify(sapisid)}, 'https://www.youtube.com');\n        if (!authHash) return { error: 'auth', message: 'Not logged in (SAPISID cookie missing)' };\n\n        const resp = await fetch('/youtubei/v1/like/removelike?key=' + apiKey + '&prettyPrint=false', {\n          method: 'POST',\n          credentials: 'include',\n          headers: {\n            'Content-Type': 'application/json',\n            'Authorization': authHash,","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/youtube/unlike.js#L7-L43","documentation":"AuthRequiredError thrown before the unlike command runs because no SAPISID cookie exists for www.youtube.com. The SAPISID cookie is only set when the browser profile is signed into a YouTube/Google account, and it is required to build the SAPISIDHASH authorization header for YouTube's internal APIs. The library throws this instead of letting the API call fail later so the caller can prompt for login.","triggerScenarios":"Calling the youtube unlike command while the automation browser profile is not logged into YouTube, or the profile's cookies were cleared/expired so readYoutubeSapisid(page) returns a falsy value.","commonSituations":"Running headless automation with a fresh (never-logged-in) browser profile; Google signed the user out; cookie store wiped between runs; using a profile for a different Google account without YouTube session; incognito context with no persistent cookies.","solutions":["Log into www.youtube.com in the browser profile used by the automation (interactively or by loading a persistent profile with valid Google cookies).","Re-run readYoutubeSapisid / verify the SAPISID cookie exists for www.youtube.com before invoking the command.","Point the tool at a persistent user-data-dir profile that retains YouTube session cookies instead of a fresh ephemeral context.","Re-authenticate if Google expired the session, then retry the unlike command."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const sapisid = await readYoutubeSapisid(page);\nif (!sapisid) throw new Error('YouTube login required: SAPISID cookie missing');","typeGuard":null,"tryCatchPattern":"try {\n  await unlike({ url });\n} catch (e) {\n  if (e.name === 'AuthRequiredError') {\n    await loginToYoutube(browserProfile);\n    return unlike({ url });\n  }\n  throw e;\n}","preventionTips":["Run the tool against a persistent, already-logged-in browser profile (user-data-dir) rather than an ephemeral context.","Pre-flight check the SAPISID cookie exists for www.youtube.com before issuing commands.","Handle Google session expiry by detecting AuthRequiredError and triggering re-login.","Avoid clearing cookies between automation runs."],"tags":["auth","youtube","cookies","login-required"],"backgroundTag":"sapisid-cookie-missing","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}