{"record":{"id":"0f32b2d045c899de","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-weibo-delete","errorCode":null,"errorMessage":"Browser session required for weibo delete","messagePattern":"Browser session required for weibo delete","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/weibo/delete.js","lineNumber":61,"sourceCode":"cli({\n    site: 'weibo',\n    name: 'delete',\n    access: 'write',\n    description: 'Delete one of my Weibo posts by id',\n    domain: 'weibo.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        {\n            name: 'id',\n            required: true,\n            positional: true,\n            help: 'Post ID (numeric idstr or mblogid from URL / weibo me / weibo post output)',\n        },\n    ],\n    columns: ['status', 'id', 'mblogid'],\n    func: async (page, kwargs) => {\n        if (!page) {\n            throw new CommandExecutionError('Browser session required for weibo delete');\n        }\n        const raw = String(kwargs.id ?? '').trim();\n        const id = normalizePostId(raw);\n        await page.goto('https://weibo.com');\n        await page.wait(2);\n        const result = requireObjectEvaluateResult(unwrapEvaluateResult(await page.evaluate(`\n      (async () => {\n        const input = ${JSON.stringify(id)};\n        const readCookie = (name) => {\n          const pair = document.cookie.split(';').map(s => s.trim()).find(s => s.startsWith(name + '='));\n          return pair ? decodeURIComponent(pair.slice(name.length + 1)) : '';\n        };\n        // Step 1: resolve mblogid / idstr to canonical idstr via /show.\n        const showResp = await fetch('/ajax/statuses/show?id=' + encodeURIComponent(input), { credentials: 'include' });\n        if (showResp.status === 401 || showResp.status === 403) {\n          return { ok: false, error: 'auth', status: showResp.status };\n        }\n        // 404 from /show means the post does not exist (deleted, wrong id, or","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/delete.js#L43-L79","documentation":"The weibo delete command's func requires an authenticated browser page; the CLI framework injects it only when a browser session is active. If page is null/falsy, there is no browser to perform the in-page delete API call, so the command throws CommandExecutionError up front instead of failing later mid-flow.","triggerScenarios":"Running `weibo delete` without logging in first (no `weibo login`), a browser session that crashed or was closed before the command ran, or invoking the command through a script path that bypasses session setup.","commonSituations":"Fresh installs where login was never run, expired/crashed browser sessions between commands, running the command in CI without a logged-in browser profile, or headless environment misconfiguration that prevents the session from being restored.","solutions":["Run `weibo login` first to establish an authenticated browser session, then retry delete","Check that the browser process/session from login is still alive; re-login if it crashed","Persist/reuse the same browser profile directory so sessions survive across CLI invocations","Ensure the automation environment (headful/headless config) allows the session browser to launch"],"exampleFix":"// before\nweibo delete --id 5012345678901   // no session\n// after\nweibo login\nweibo delete --id 5012345678901","handlingStrategy":"try-catch","validationCode":"// ensure a session exists before invoking delete\nif (!await hasWeiboSession(page)) {\n  throw new Error('run `weibo login` before `weibo delete`');\n}","typeGuard":"function isMissingSessionError(err) {\n  return err instanceof CommandExecutionError && /Browser session required/.test(err.message);\n}","tryCatchPattern":"try {\n  await cliDelete({ id });\n} catch (err) {\n  if (isMissingSessionError(err)) {\n    await cliLogin();            // establish browser session\n    await cliDelete({ id });     // retry once\n  } else throw err;\n}","preventionTips":["Always run `weibo login` before session-scoped commands like delete","Reuse a persistent browser profile so sessions survive across invocations","Check session liveness (e.g. run `weibo me`) before destructive commands","In CI, restore a pre-authenticated profile or perform login as a setup step"],"tags":["weibo","browser-session","authentication"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}