{"record":{"id":"cdb0796645f22e64","repo":"jackwener/OpenCLI","slug":"chrome-1688-action","errorCode":null,"errorMessage":"请先在共享 Chrome 完成 1688 登录/验证，再重试（${action}）","messagePattern":"请先在共享 Chrome 完成 1688 登录/验证，再重试（(.+?)）","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/1688/shared.js","lineNumber":413,"sourceCode":"    }\n    catch (error) {\n        const message = error instanceof Error ? error.message : String(error);\n        if (message.includes('Inspected target navigated or closed')\n            || message.includes('Cannot find context with specified id')\n            || message.includes('Target closed')) {\n            throw new CommandExecutionError(`1688 ${action} navigation lost the current browser target`, `${buildCaptchaHint(action)} If CDP is attached to a stale or blocked tab, open a fresh 1688 tab and point OPENCLI_CDP_TARGET at that tab.`);\n        }\n        throw error;\n    }\n}\nexport async function ensure1688Session(page) {\n    const state = await gotoAndReadState(page, HOME_URL, 1500, 'homepage');\n    assertAuthenticatedState(state, 'homepage');\n}\nexport function assertAuthenticatedState(state, action) {\n    if (!isCaptchaState(state) && !isLoginState(state))\n        return;\n    throw new AuthRequiredError('1688.com', `请先在共享 Chrome 完成 1688 登录/验证，再重试（${action}）`);\n}\nexport function assertNotCaptcha(state, action) {\n    assertAuthenticatedState(state, action);\n}\nexport function toNumber(value) {\n    if (typeof value === 'number' && Number.isFinite(value)) {\n        return value;\n    }\n    if (typeof value === 'string') {\n        const normalized = value.replace(/,/g, '').trim();\n        if (!normalized)\n            return null;\n        const parsed = Number.parseFloat(normalized);\n        return Number.isFinite(parsed) ? parsed : null;\n    }\n    return null;\n}\nexport function limitCandidates(values, limit) {","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/1688/shared.js#L395-L431","documentation":"assertAuthenticatedState inspects the read page state and throws AuthRequiredError when the state looks like a 1688 captcha or login wall. The library requires a logged-in, captcha-free shared Chrome session for 1688 operations, so it fails fast with instructions (in Chinese) rather than scraping garbage from a verification page.","triggerScenarios":"Calling any 1688 command whose flow calls ensure1688Session/assertAuthenticatedState while the shared Chrome tab shows 1688's login page or a slider/captcha challenge — e.g. session cookies expired, IP flagged, or the user logged out.","commonSituations":"1688 cookie/session expired overnight; shared Chrome never logged into 1688; datacenter IP triggering anti-bot captcha; account forced logout; automation hitting the site too aggressively.","solutions":["Open the shared Chrome instance, log in to 1688.com and complete any slider/captcha verification manually, then rerun the command (action name in the message shows which step failed).","Confirm the CDP target tab actually shows 1688 logged-in state (not a login wall) before retrying.","Slow down request rate / change to a cleaner network or a warm session if captchas recur."],"exampleFix":"// before\nopencli 1688 store https://shop.1688.com/ // -> AuthRequiredError, session is a login wall\n// after logging in + captcha in shared Chrome\nopencli 1688 store https://shop.1688.com/","handlingStrategy":"try-catch","validationCode":"// precheck: is the session logged in and captcha-free before running commands?\nconst state = await readCurrent1688State();\nconst ok = !(await import('./clis/1688/shared.js')).isCaptchaState(state)\n  && !(await import('./clis/1688/shared.js')).isLoginState(state);\nif (!ok) throw new Error('Complete 1688 login/captcha in shared Chrome first');","typeGuard":"function isAuthed1688State(state) {\n  return Boolean(state && !state.isLoginWall && !state.isCaptcha);\n}","tryCatchPattern":"try {\n  await run1688Command();\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    console.error('Action needed: open shared Chrome, log into 1688.com and finish the slider/captcha, then retry.');\n    // optionally open the login page for the user\n  } else throw e;\n}","preventionTips":["Check login state at session start before running batch jobs.","Keep the shared Chrome 1688 session warm; re-login periodically.","Avoid datacenter IPs that trigger captchas; prefer a residential/warm session.","Throttle request rates to reduce anti-bot challenges."],"tags":["auth","captcha","session-expired","anti-bot"],"backgroundTag":"login-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}