{"record":{"id":"87f4401924afd061","repo":"jackwener/OpenCLI","slug":"document-cookie-is-empty-trae-uses-electron-sessi","errorCode":null,"errorMessage":"document.cookie is empty (Trae uses Electron session cookies, mostly httpOnly).","messagePattern":"document\\.cookie is empty \\(Trae uses Electron session cookies, mostly httpOnly\\)\\.","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"info","filePath":"clis/trae-solo/renderer-storage.js","lineNumber":125,"sourceCode":"        ];\n    },\n});\n\n// -------- cookies --------\ncli({\n    site: 'trae-solo',\n    name: 'cookies',\n    access: 'read',\n    description: 'List cookies on the Trae SOLO renderer (JS-visible via document.cookie; httpOnly cookies not shown).',\n    domain: 'localhost',\n    strategy: Strategy.UI,\n    browser: true,\n    args: [],\n    columns: ['Index', 'Key', 'Bytes', 'Name', 'Preview', 'Database', 'Version'],\n    func: async (page) => {\n        const raw = await page.evaluate('document.cookie');\n        if (!raw) {\n            throw new EmptyResultError('trae-solo cookies', 'document.cookie is empty (Trae uses Electron session cookies, mostly httpOnly).');\n        }\n        const cookies = raw.split('; ').map((pair) => {\n            const idx = pair.indexOf('=');\n            if (idx < 0) return { name: pair, value: '' };\n            return { name: pair.slice(0, idx), value: pair.slice(idx + 1) };\n        });\n        return cookies.map((c, i) => ({\n            Index: i + 1,\n            Key: '',\n            Name: c.name,\n            Bytes: c.value.length,\n            Preview: c.value.slice(0, 40) + (c.value.length > 40 ? '…' : ''),\n            Database: '',\n            Version: '',\n        }));\n    },\n});\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trae-solo/renderer-storage.js#L107-L143","documentation":"EmptyResultError from the trae-solo `cookies` command when `document.cookie` evaluates to an empty string. In Electron apps like Trae, most session cookies are set httpOnly and are invisible to document.cookie, so this is an expected limitation rather than a broken page — the library surfaces it explicitly instead of returning an empty table.","triggerScenarios":"Running the cookies command on a Trae renderer whose cookies are all httpOnly or SameSite-protected; a fresh profile with no non-httpOnly cookies set; a page context where no document cookies were written at all.","commonSituations":"Developers trying to extract auth/session cookies for debugging or API replay — Electron apps typically keep these out of JS reach by design; testing on a brand-new workspace before any cookie-setting request.","solutions":["Use Trae's CDP/DevTools Network.getCookies (via the browser backend) instead of document.cookie to read httpOnly cookies.","Check DevTools → Application → Cookies to confirm which cookies exist and their flags.","If you control the app, mark needed cookies non-httpOnly (not recommended for auth cookies).","Treat the empty result as expected and use another channel (network request capture) for session data."],"exampleFix":"// before\nconst cookies = await cli('trae-solo', 'cookies'); // EmptyResultError\n// after\nconst cdp = await page.context().newCDPSession(page);\nconst { cookies } = await cdp.send('Network.getCookies'); // includes httpOnly","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const hasJsCookies = (raw) => typeof raw === 'string' && raw.trim().length > 0;","tryCatchPattern":"try {\n  cookies = await cli('trae-solo', 'cookies');\n} catch (e) {\n  if (/document.cookie is empty/.test(e.message)) {\n    console.warn('Cookies are httpOnly; use CDP Network.getCookies instead');\n    cookies = await getCookiesViaCDP(page);\n  } else throw e;\n}","preventionTips":["Assume Electron session cookies are httpOnly and unreachable from document.cookie.","Use CDP Network.getAllCookies / DevTools Application panel for cookie inspection.","Don't build auth flows that depend on reading httpOnly cookies from JS.","Check cookies exist (non-httpOnly ones) before relying on this command's output."],"tags":["cookies","httponly","electron","trae"],"backgroundTag":"document-cookie-empty","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}