{"record":{"id":"8fadbd25eb2d080b","repo":"jackwener/OpenCLI","slug":"taobao-add-cart-requires-a-logged-in-taobao-sessio","errorCode":null,"errorMessage":"taobao add-cart requires a logged-in Taobao session","messagePattern":"taobao add-cart requires a logged-in Taobao session","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/taobao/add-cart.js","lineNumber":134,"sourceCode":"        for (let i = 0; i < 10; i++) {\n          await new Promise(r => setTimeout(r, 500));\n          const text = document.body?.innerText || '';\n          if (text.includes('已加入购物车') || text.includes('商品已成功') || text.includes('去购物车结算') || text.includes('去购物车')) {\n            return 'success';\n          }\n          if (text.includes('请选择') || text.includes('请先选择')) {\n            return 'need_spec';\n          }\n          if (text.includes('请登录')) {\n            return 'login_required';\n          }\n        }\n        if (location.href.includes('cart')) return 'success';\n        return 'unknown';\n      })()\n    `);\n        if (result === 'login_required') {\n            throw new AuthRequiredError('taobao add-cart requires a logged-in Taobao session');\n        }\n        let status = '? 未确认';\n        if (result === 'success')\n            status = '✓ 已加入购物车';\n        else if (result === 'need_spec')\n            status = '✗ 需要选择更多规格';\n        const selectedSpec = Array.isArray(selectResult) ? selectResult.join(' | ') : '';\n        return [{\n                status,\n                title: info?.title || '',\n                price: info?.price || '',\n                selected_spec: selectedSpec || '(未选择)',\n                item_id: itemId,\n            }];\n    },\n});\n","sourceCodeStart":116,"sourceCodeEnd":151,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/taobao/add-cart.js#L116-L151","documentation":"In the taobao add-cart command, after clicking the add-to-cart button the page's text is scanned for success/spec/login markers. If it detects '请登录' (please log in), the command throws AuthRequiredError because adding to cart requires an authenticated Taobao session.","triggerScenarios":"The in-page detector finds '请登录' in document.body.innerText within the 10x500ms polling window after clicking '加入购物车' — the browser profile has no valid Taobao login, so Taobao demands login at cart time.","commonSituations":"Fresh browser profile never logged into Taobao; expired Taobao session (cookies stale); Taobao forcing re-login on sensitive actions like cart adds; running the command before `taobao auth login`.","solutions":["Run the Taobao login command (`taobao auth login`) and complete QR/password login in the browser.","Verify the session with `taobao auth status` (tracknick cookie present) before retrying add-cart.","Retry add-cart after login; if it still demands login, clear cookies and log in again.","Check that the profile used by the CLI is the one you logged into."],"exampleFix":"// before: attempting add-cart on an anonymous profile\nawait addCart(page, itemId);\n// after: verify session first\nimport { verifyTaobaoIdentity } from '../taobao/auth.js';\ntry { await verifyTaobaoIdentity(page); await addCart(page, itemId); }\ncatch (e) { if (e instanceof AuthRequiredError) { await taobaoLogin(page); return addCart(page, itemId); } throw e; }","handlingStrategy":"validation","validationCode":"// run before add-cart\nimport { verifyTaobaoIdentity } from '../taobao/auth.js';\nawait verifyTaobaoIdentity(page); // throws AuthRequiredError early if not logged in","typeGuard":null,"tryCatchPattern":"try {\n  await addCart(page, itemId);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await taobaoLogin(page);   // complete interactive login\n    return addCart(page, itemId);\n  }\n  throw e;\n}","preventionTips":["Verify Taobao session (`taobao auth status`) before cart operations","Use a persistent browser profile with a valid login","Re-login when sessions age out"],"tags":["auth","taobao","session-required","login"],"backgroundTag":"login-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}