{"record":{"id":"0075ce39cb884cb9","repo":"musistudio/claude-code-router","slug":"chrome-login-import-payload-must-be-an-object","errorCode":null,"errorMessage":"Chrome login import payload must be an object.","messagePattern":"Chrome login import payload must be an object\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/electron/src/main/chrome-login-import.ts","lineNumber":441,"sourceCode":"  return `${secure ? \"https\" : \"http\"}://${host}${normalizedPath}`;\n}\n\nfunction cookieDomainMatches(cookieHost: string, allowedDomain: string): boolean {\n  return cookieHost === allowedDomain || cookieHost.endsWith(`.${allowedDomain}`);\n}\n\nfunction normalizeSameSite(value: unknown): CookieSetDetails[\"sameSite\"] | undefined {\n  return value === \"lax\" || value === \"strict\" || value === \"no_restriction\" || value === \"unspecified\"\n    ? value\n    : undefined;\n}\n\nfunction readImportPayload(payload: unknown): {\n  cookies: ChromeLoginImportCookie[];\n  localStorage: ChromeLoginImportLocalStorage[];\n} {\n  if (!isRecord(payload)) {\n    throw new Error(\"Chrome login import payload must be an object.\");\n  }\n  const cookies = Array.isArray(payload.cookies)\n    ? payload.cookies.filter(isRecord) as ChromeLoginImportCookie[]\n    : [];\n  const localStorage = Array.isArray(payload.localStorage)\n    ? payload.localStorage.filter(isRecord) as ChromeLoginImportLocalStorage[]\n    : [];\n  if (cookies.length === 0 && localStorage.length === 0) {\n    throw new Error(\"Chrome login import payload must include cookies or localStorage.\");\n  }\n  return { cookies, localStorage };\n}\n\nfunction cloneJob(job: StoredChromeLoginImportJob): ChromeLoginImportJob {\n  return {\n    ...job,\n    domains: [...job.domains],\n    ...(job.result","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/electron/src/main/chrome-login-import.ts#L423-L459","documentation":"The IPC/HTTP import payload handler validates that the incoming JSON body is a plain object before reading cookies/localStorage arrays. Any non-object JSON (array, string, number, null, or malformed structure) is rejected early rather than crashing deeper in the import pipeline.","triggerScenarios":"POSTing a JSON body like \"[...]\", \"null\", or \"\\\"text\\\"\" to the import endpoint; a serializer bug on the exporter side emitting a top-level array or primitive.","commonSituations":"Client serializes with JSON.stringify on the wrong variable; double-encoded JSON (a JSON string of JSON); hand-crafted curl payloads missing the outer braces.","solutions":["Ensure the request body is a JSON object: { \"cookies\": [...], \"localStorage\": [...] }","If JSON may be double-encoded, JSON.parse once before sending","Log the parsed typeof in a wrapper to catch serializer bugs"],"exampleFix":"// before\nawait post(JSON.stringify(JSON.stringify(payload)));\n\n// after\nawait post(JSON.stringify({ cookies: payload.cookies ?? [], localStorage: payload.localStorage ?? [] }));","handlingStrategy":"type-guard","validationCode":"if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) {\n  throw new TypeError('Import payload must be a JSON object');\n}","typeGuard":"function isImportPayloadObject(value: unknown): value is Record<string, unknown> {\n  return typeof value === 'object' && value !== null && !Array.isArray(value);\n}","tryCatchPattern":"try { await importPayload(raw); } catch (e) { if (e instanceof Error && e.message === 'Chrome login import payload must be an object.') { /* fix serializer, resend */ } else throw e; }","preventionTips":["Type the sender side against a payload interface","Beware double JSON.stringify producing a top-level string","Validate shape client-side before POSTing"],"tags":["validation","json","payload","ipc"],"backgroundTag":"request-payload-validation-failed","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}