{"record":{"id":"e38109f67e3c377a","repo":"jackwener/OpenCLI","slug":"xiaohongshu-collection-interceptor-returned-malfor","errorCode":null,"errorMessage":"xiaohongshu collection interceptor returned malformed captures","messagePattern":"xiaohongshu collection interceptor returned malformed captures","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/collection-helpers.js","lineNumber":206,"sourceCode":"    const payload = unwrapBrowserResult(await page.evaluate(CURRENT_LOCATION_JS));\n    if (!isObject(payload)) {\n        throw new CommandExecutionError('xiaohongshu collection page returned malformed location');\n    }\n    const hostname = toCleanString(payload.hostname).toLowerCase();\n    const pathname = toCleanString(payload.pathname);\n    if (hostname === 'www.xiaohongshu.com' && pathname === '/login') {\n        throw new AuthRequiredError('xiaohongshu collection page requires login');\n    }\n    const expectedPath = `/user/profile/${toCleanString(userId)}`;\n    if (hostname !== 'www.xiaohongshu.com' || pathname !== expectedPath) {\n        throw new CommandExecutionError(`xiaohongshu collection landed on unexpected page: ${toCleanString(payload.href) || `${hostname}${pathname}`}`);\n    }\n}\n\nasync function accumulateInterceptedNotes(page, bucket, fallbackUserId) {\n    const reqs = await page.getInterceptedRequests();\n    if (!Array.isArray(reqs)) {\n        throw new CommandExecutionError('xiaohongshu collection interceptor returned malformed captures');\n    }\n    if (Array.isArray(reqs) && reqs.length > 0)\n        bucket.push(...reqs);\n    return extractNotesFromResponses(bucket, fallbackUserId);\n}\n\nexport async function resolveXhsUserId(page, rawId) {\n    if (rawId)\n        return normalizeXhsUserId(String(rawId));\n    await page.goto('https://www.xiaohongshu.com/explore');\n    await page.wait(2);\n    await throwIfLoginWall(page);\n    const userId = unwrapBrowserResult(await page.evaluate(`() => {\n      const user = window.__INITIAL_STATE__?.user?.userInfo;\n      const info = user?._value ?? user ?? {};\n      return info.user_id || info.userId || info.userID || '';\n    }`));\n    const clean = toCleanString(userId);","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/collection-helpers.js#L188-L224","documentation":"accumulateInterceptedNotes reads all captured network requests via page.getInterceptedRequests() and requires an array back. A non-array result means the interception API behaved unexpectedly (failed, wrong driver version, interception not installed), so CommandExecutionError is thrown. Without captures, no collection notes can be extracted.","triggerScenarios":"page.getInterceptedRequests() resolves to undefined/null or a non-array because request interception wasn't enabled before navigation, the page object isn't the automation wrapper's expected type, or the driver changed its return shape.","commonSituations":"Forgetting to enable network interception before page.goto; passing a raw puppeteer/playwright page where the wrapper expects its own extended page; upgrading the browser-automation library so getInterceptedRequests no longer exists/returns differently.","solutions":["Enable request interception before navigating to the collection page","Confirm the page object is created by the same automation wrapper that defines getInterceptedRequests","Log typeof result and its constructor to diagnose the driver's return shape after upgrades","Re-run with a freshly launched browser — corrupted interception state can return undefined"],"exampleFix":"// before\nawait page.goto(url);\nconst rows = await accumulateInterceptedNotes(page, bucket, userId); // reqs undefined\n// after\nawait page.enableRequestInterception([collectionApiPattern]); // must precede goto\nawait page.goto(url, { waitUntil: 'networkidle' });\nconst rows = await accumulateInterceptedNotes(page, bucket, userId);","handlingStrategy":"type-guard","validationCode":"if (typeof page.getInterceptedRequests !== 'function') throw new Error('interception unsupported: wrong page wrapper?');\nconst reqs = await page.getInterceptedRequests();\nif (!Array.isArray(reqs)) throw new Error('interceptor returned ' + typeof reqs);","typeGuard":"const isRequestArray = (v) => Array.isArray(v);","tryCatchPattern":"try { rows = await accumulateInterceptedNotes(page, bucket, userId); } catch (e) { if (String(e.message).includes('malformed captures')) { throw new Error('request interception not active — enable it before page.goto'); } throw e; }","preventionTips":["Enable network interception before any navigation","Only pass page objects from the wrapper that implements getInterceptedRequests","After driver upgrades, smoke-test that intercepted requests are returned as arrays","Verify interception state on a fresh browser profile if undefined results appear"],"tags":["network-interception","scraping","command-execution-error","browser-automation"],"backgroundTag":"network-interception-not-enabled","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}