{"record":{"id":"fe4701ff1d3ddf77","repo":"jackwener/OpenCLI","slug":"linkedin-cookie-lookup-returned-malformed-payload","errorCode":null,"errorMessage":"LinkedIn cookie lookup returned malformed payload","messagePattern":"LinkedIn cookie lookup returned malformed payload","errorType":"error_code","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/linkedin/people-search.js","lineNumber":209,"sourceCode":"        if (!page) throw new CommandExecutionError('Browser session required for linkedin people-search');\n        const keywords = requireStringArg(args, 'keywords', '--keywords');\n        const limit = parseLimit(args.limit);\n\n        try {\n            await page.goto(buildSearchUrl(keywords));\n            await page.wait(6);\n        } catch (error) {\n            throw new CommandExecutionError(`LinkedIn people search navigation failed: ${error?.message || error}`);\n        }\n\n        let cookies;\n        try {\n            cookies = await page.getCookies({ url: 'https://www.linkedin.com' });\n        } catch (error) {\n            throw new CommandExecutionError(`LinkedIn cookie lookup failed: ${error?.message || error}`);\n        }\n        if (!Array.isArray(cookies)) {\n            throw new CommandExecutionError('LinkedIn cookie lookup returned malformed payload');\n        }\n        const jsession = cookies.find((c) => c.name === 'JSESSIONID')?.value;\n        if (!jsession) {\n            throw new AuthRequiredError(LINKEDIN_DOMAIN, 'LinkedIn JSESSIONID cookie not found. Please sign in to LinkedIn in the browser.');\n        }\n\n        let result;\n        try {\n            result = unwrapEvaluateResult(await page.evaluate(extractionScript()));\n        } catch (error) {\n            throw new CommandExecutionError(`LinkedIn people search extraction failed: ${error?.message || error}`);\n        }\n        if (result?.error) {\n            if (looksLinkedInAuthWall(`${result.url || ''} ${result.error || ''}`)) {\n                throw new AuthRequiredError(LINKEDIN_DOMAIN, 'LinkedIn people search requires an active signed-in browser session.');\n            }\n            // If LinkedIn redirected away from the search page that\n            // usually means CUL was reached or the account is gated.","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/people-search.js#L191-L227","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use the supported/up-to-date browser automation client whose getCookies returns an array","Fix test mocks/stubs to return an array of {name, value} cookie objects","Wrap custom page implementations to normalize getCookies output to an array","Check adapter version compatibility with this CLI version"],"exampleFix":"// before: mock returns wrong shape\nconst page = { getCookies: async () => ({ JSESSIONID: 'abc' }) };\n// after: mock matches real contract\nconst page = { getCookies: async () => [{ name: 'JSESSIONID', value: 'abc' }] };","handlingStrategy":"type-guard","validationCode":"const raw = await page.getCookies({ url: 'https://www.linkedin.com' });\nif (!Array.isArray(raw)) throw new Error('automation client returned non-array cookies; fix adapter or mock');","typeGuard":"const isCookieArray = (v) => Array.isArray(v) && v.every((c) => c && typeof c.name === 'string' && typeof c.value === 'string');","tryCatchPattern":"try { cookies = normalizeCookies(await page.getCookies({ url: LI })); }\ncatch (e) { if (e instanceof TypeError) cookies = Object.values(await page.getCookies({ url: LI })); else throw e; }","preventionTips":["Use the officially supported automation client version","In tests, stub getCookies with the real contract: array of {name, value}","Wrap custom page adapters to normalize cookie output to arrays","Pin adapter versions and read changelogs for breaking getCookies changes"],"tags":["cookies","linkedin","payload-validation","contract-mismatch"],"backgroundTag":"malformed-cookie-payload","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}