jackwener/OpenCLI · error · CommandExecutionError

LinkedIn cookie lookup returned malformed payload

Error message

LinkedIn cookie lookup returned malformed payload

What it means

page.getCookies is expected to return an array of cookie objects. If it returns anything else (null, undefined, a plain object), the library treats the response as structurally invalid and throws CommandExecutionError 'LinkedIn cookie lookup returned malformed payload'.

Source

Thrown at clis/linkedin/people-search.js:209

        if (!page) throw new CommandExecutionError('Browser session required for linkedin people-search');
        const keywords = requireStringArg(args, 'keywords', '--keywords');
        const limit = parseLimit(args.limit);

        try {
            await page.goto(buildSearchUrl(keywords));
            await page.wait(6);
        } catch (error) {
            throw new CommandExecutionError(`LinkedIn people search navigation failed: ${error?.message || error}`);
        }

        let cookies;
        try {
            cookies = await page.getCookies({ url: 'https://www.linkedin.com' });
        } catch (error) {
            throw new CommandExecutionError(`LinkedIn cookie lookup failed: ${error?.message || error}`);
        }
        if (!Array.isArray(cookies)) {
            throw new CommandExecutionError('LinkedIn cookie lookup returned malformed payload');
        }
        const jsession = cookies.find((c) => c.name === 'JSESSIONID')?.value;
        if (!jsession) {
            throw new AuthRequiredError(LINKEDIN_DOMAIN, 'LinkedIn JSESSIONID cookie not found. Please sign in to LinkedIn in the browser.');
        }

        let result;
        try {
            result = unwrapEvaluateResult(await page.evaluate(extractionScript()));
        } catch (error) {
            throw new CommandExecutionError(`LinkedIn people search extraction failed: ${error?.message || error}`);
        }
        if (result?.error) {
            if (looksLinkedInAuthWall(`${result.url || ''} ${result.error || ''}`)) {
                throw new AuthRequiredError(LINKEDIN_DOMAIN, 'LinkedIn people search requires an active signed-in browser session.');
            }
            // If LinkedIn redirected away from the search page that
            // usually means CUL was reached or the account is gated.

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use the supported/up-to-date browser automation client whose getCookies returns an array
  2. Fix test mocks/stubs to return an array of {name, value} cookie objects
  3. Wrap custom page implementations to normalize getCookies output to an array
  4. Check adapter version compatibility with this CLI version

Example fix

// before: mock returns wrong shape
const page = { getCookies: async () => ({ JSESSIONID: 'abc' }) };
// after: mock matches real contract
const page = { getCookies: async () => [{ name: 'JSESSIONID', value: 'abc' }] };
Defensive patterns

Strategy: type-guard

Validate before calling

const raw = await page.getCookies({ url: 'https://www.linkedin.com' });
if (!Array.isArray(raw)) throw new Error('automation client returned non-array cookies; fix adapter or mock');

Type guard

const isCookieArray = (v) => Array.isArray(v) && v.every((c) => c && typeof c.name === 'string' && typeof c.value === 'string');

Try / catch

try { cookies = normalizeCookies(await page.getCookies({ url: LI })); }
catch (e) { if (e instanceof TypeError) cookies = Object.values(await page.getCookies({ url: LI })); else throw e; }

Prevention

When it happens

Trigger: page.getCookies({ url: 'https://www.linkedin.com' }) resolves to a non-array value — e.g. a custom/older automation client returning an object map of cookies, a wrapper returning undefined on error, or a shimmed page implementation.

Common situations: Using a non-standard or outdated browser automation adapter whose getCookies signature differs; mocking the page in tests and returning a wrong-shaped cookies value; a proxy client that swallows errors and returns undefined.

Understand the failure class

Related errors


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