{"record":{"id":"ecba475dbf95d21c","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-weibo-publish","errorCode":null,"errorMessage":"Browser session required for weibo publish","messagePattern":"Browser session required for weibo publish","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/weibo/publish.js","lineNumber":96,"sourceCode":"    browser: true,\n    args: [\n        {\n            name: 'text',\n            type: 'string',\n            required: true,\n            positional: true,\n            help: 'Weibo text content (max 2000 chars)',\n        },\n        {\n            name: 'images',\n            type: 'string',\n            required: false,\n            help: `Image paths, comma-separated, max ${MAX_IMAGES} (jpg/png/gif/webp)`,\n        },\n    ],\n    columns: ['status', 'message', 'text'],\n    func: async (page, kwargs) => {\n        if (!page) throw new CommandExecutionError('Browser session required for weibo publish');\n\n        const text = validateText(kwargs.text);\n        const absPaths = validateImagePaths(kwargs.images);\n\n        // Step 1: Navigate to weibo.com and wait for feed to load\n        await page.goto('https://weibo.com', { waitUntil: 'load', settleMs: 2000 });\n        await page.wait({ time: 2 });\n\n        // Step 2: Check login\n        try {\n            await getSelfUid(page);\n        } catch (err) {\n            if (err instanceof AuthRequiredError) throw err;\n            throw new CommandExecutionError('Not logged into Weibo. Please login at weibo.com in your Chrome browser.');\n        }\n\n        // Step 3: Click \"发微博\" button to open inline compose editor\n        const clickResult = await page.evaluate(`","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/publish.js#L78-L114","documentation":"The publish command runs through a browser session provided by a Chrome extension; if the `page` handle is not available (no browser session attached), func throws this CommandExecutionError before doing anything.","triggerScenarios":"Running `weibo publish` outside a connected browser session — extension not installed/disabled, no active Chrome tab managed by the tool, or session dropped before the call.","commonSituations":"Running in CI without the extension; forgetting to start/connect the browser session; the extension failing to inject after a Chrome update.","solutions":["Install/enable the companion Chrome extension and reconnect the session","Start a browser session before running the publish command","Update the extension and CLI to matching versions"],"exampleFix":"// before\nweibo publish --text \"hi\"   # no session\n// after\n<open managed Chrome session with extension>\nweibo publish --text \"hi\"","handlingStrategy":"fallback","validationCode":"// ensure a managed browser session exists before invoking the CLI\nif (!session || !session.page) {\n  throw new Error('start the browser session / install the extension first');\n}","typeGuard":"function hasPage(ctx) {\n  return ctx != null && typeof ctx === 'object' && typeof ctx.page === 'object' && ctx.page !== null;\n}","tryCatchPattern":"try {\n  await cli.run(['weibo', 'publish', '--text', text]);\n} catch (err) {\n  if (/Browser session required/.test(err.message)) {\n    await startBrowserSession(); // connect Chrome with extension\n    // then retry\n  } else throw err;\n}","preventionTips":["Install and enable the companion Chrome extension","Always open the managed session before publish commands","Keep extension and CLI versions in sync"],"tags":["browser-automation","session","weibo"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}