jackwener/OpenCLI · info · EmptyResultError

document.cookie is empty (Trae uses Electron session cookies

Error message

document.cookie is empty (Trae uses Electron session cookies, mostly httpOnly).

What it means

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.

Source

Thrown at clis/trae-solo/renderer-storage.js:125

        ];
    },
});

// -------- cookies --------
cli({
    site: 'trae-solo',
    name: 'cookies',
    access: 'read',
    description: 'List cookies on the Trae SOLO renderer (JS-visible via document.cookie; httpOnly cookies not shown).',
    domain: 'localhost',
    strategy: Strategy.UI,
    browser: true,
    args: [],
    columns: ['Index', 'Key', 'Bytes', 'Name', 'Preview', 'Database', 'Version'],
    func: async (page) => {
        const raw = await page.evaluate('document.cookie');
        if (!raw) {
            throw new EmptyResultError('trae-solo cookies', 'document.cookie is empty (Trae uses Electron session cookies, mostly httpOnly).');
        }
        const cookies = raw.split('; ').map((pair) => {
            const idx = pair.indexOf('=');
            if (idx < 0) return { name: pair, value: '' };
            return { name: pair.slice(0, idx), value: pair.slice(idx + 1) };
        });
        return cookies.map((c, i) => ({
            Index: i + 1,
            Key: '',
            Name: c.name,
            Bytes: c.value.length,
            Preview: c.value.slice(0, 40) + (c.value.length > 40 ? '…' : ''),
            Database: '',
            Version: '',
        }));
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use Trae's CDP/DevTools Network.getCookies (via the browser backend) instead of document.cookie to read httpOnly cookies.
  2. Check DevTools → Application → Cookies to confirm which cookies exist and their flags.
  3. If you control the app, mark needed cookies non-httpOnly (not recommended for auth cookies).
  4. Treat the empty result as expected and use another channel (network request capture) for session data.

Example fix

// before
const cookies = await cli('trae-solo', 'cookies'); // EmptyResultError
// after
const cdp = await page.context().newCDPSession(page);
const { cookies } = await cdp.send('Network.getCookies'); // includes httpOnly
Defensive patterns

Strategy: try-catch

Type guard

const hasJsCookies = (raw) => typeof raw === 'string' && raw.trim().length > 0;

Try / catch

try {
  cookies = await cli('trae-solo', 'cookies');
} catch (e) {
  if (/document.cookie is empty/.test(e.message)) {
    console.warn('Cookies are httpOnly; use CDP Network.getCookies instead');
    cookies = await getCookiesViaCDP(page);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/87f4401924afd061. Report an issue: GitHub.