{"record":{"id":"6ea4eff97951ed39","repo":"jackwener/OpenCLI","slug":"xianyu-label-returned-malformed-browser-payload","errorCode":null,"errorMessage":"Xianyu ${label} returned malformed browser payload","messagePattern":"Xianyu (.+?) returned malformed browser payload","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/im.js","lineNumber":44,"sourceCode":"    }\n    const n = Number(raw);\n    if (!Number.isSafeInteger(n) || n < 1) {\n        throw new ArgumentError('xianyu rank must be a positive integer from xianyu inbox');\n    }\n    return n;\n}\n\nexport function requireText(value, label) {\n    const text = String(value ?? '').replace(/\\s+/g, ' ').trim();\n    if (!text) {\n        throw new ArgumentError(`${label} cannot be empty`);\n    }\n    return text;\n}\n\nexport function requireEvaluateObject(payload, label) {\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n        throw new CommandExecutionError(`Xianyu ${label} returned malformed browser payload`);\n    }\n    return payload;\n}\n\nexport function requireClickResult(payload, label) {\n    const result = requireEvaluateObject(payload, label);\n    if (result.ok !== true) {\n        throw new CommandExecutionError(`Xianyu ${label} failed: ${result.reason || 'unknown-reason'}`);\n    }\n    return result;\n}\n\nexport function buildChatUrl(itemId, peerUserId) {\n    return `https://www.goofish.com/im?itemId=${encodeURIComponent(itemId)}&peerUserId=${encodeURIComponent(peerUserId)}`;\n}\n\nexport function buildInboxUrl() {\n    return 'https://www.goofish.com/im';","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/im.js#L26-L62","documentation":"This error is thrown by requireEvaluateObject when the result of a page.evaluate() browser-script call is not a non-null, non-array plain object. The library expects every injected extraction/click script to return a structured object payload; anything else (null, undefined, an array, a primitive) means the browser script failed to execute properly or the page context is broken. It is thrown as a CommandExecutionError because the browser-side command did not produce usable output.","triggerScenarios":"Calling any command that uses requireEvaluateObject (inbox, chat read, send-message, resolve-ids click, current-url read) when page.evaluate returns null/undefined, an array, or a primitive — e.g. the evaluate script threw inside the browser and the driver swallowed it into undefined, the page navigated/closed mid-evaluate, or the browser session is stale so evaluate returns nothing.","commonSituations":"Expired or crashed browser session where the page handle is dead; the goofish.com SPA navigated between goto and evaluate; a driver version change that serializes evaluate results differently (returning undefined instead of an object); calling with --resolve-ids when the conversation row click triggers a full navigation so the follow-up evaluate returns undefined.","solutions":["Re-login / restart the browser session so page.evaluate runs against a live document","Retry the command; transient SPA navigation can make evaluate return undefined once","Run without --resolve-ids to isolate whether the click-navigation path is the failing evaluate","Update the browser driver/automation runtime so evaluate results are serialized as JSON objects","Catch the error and inspect page.getCurrentUrl() to confirm the session is still on www.goofish.com/im"],"exampleFix":"// before\nconst payload = requireEvaluateObject(await page.evaluate(buildExtractInboxEvaluate(limit)), 'inbox');\n// after\nlet raw;\ntry {\n  raw = await page.evaluate(buildExtractInboxEvaluate(limit));\n} catch (e) {\n  await page.goto(buildInboxUrl());\n  await page.wait(4);\n  raw = await page.evaluate(buildExtractInboxEvaluate(limit));\n}\nconst payload = requireEvaluateObject(raw, 'inbox');","handlingStrategy":"validation","validationCode":"function isValidEvaluatePayload(v) {\n  return v !== null && typeof v === 'object' && !Array.isArray(v);\n}\n// check before using: if (!isValidEvaluatePayload(raw)) re-navigate and retry;","typeGuard":"function isEvaluateObject(v) {\n  return v !== null && typeof v === 'object' && !Array.isArray(v);\n}\nif (isEvaluateObject(raw)) { const payload = raw; /* payload is a plain object */ }","tryCatchPattern":"try {\n  const payload = requireEvaluateObject(await page.evaluate(script), 'inbox');\n} catch (e) {\n  if (String(e).includes('malformed browser payload')) {\n    await page.goto('https://www.goofish.com/im');\n    await page.wait(4);\n    // retry once, else surface the error\n  } else throw e;\n}","preventionTips":["Confirm the browser session is alive (getCurrentUrl succeeds) before calling commands that evaluate scripts","Avoid navigating the page concurrently while a command is running","Keep the automation driver updated so evaluate results serialize as JSON objects","Wrap commands in a single retry that re-navigates on payload errors"],"tags":["browser-automation","payload-validation","command-execution"],"backgroundTag":"malformed-browser-payload","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}