{"record":{"id":"70c83f4128af4b80","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-twitter-retweet","errorCode":null,"errorMessage":"Browser session required for twitter retweet","messagePattern":"Browser session required for twitter retweet","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/retweet.js","lineNumber":19,"sourceCode":"import { CommandExecutionError, TimeoutError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { parseTweetUrl, buildTwitterArticleScopeSource } from './shared.js';\n\ncli({\n    site: 'twitter',\n    name: 'retweet',\n    access: 'write',\n    description: 'Retweet a specific tweet',\n    domain: 'x.com',\n    strategy: Strategy.UI,\n    browser: true,\n    args: [\n        { name: 'url', type: 'string', required: true, positional: true, help: 'The URL of the tweet to retweet' },\n    ],\n    columns: ['status', 'message'],\n    func: async (page, kwargs) => {\n        if (!page)\n            throw new CommandExecutionError('Browser session required for twitter retweet');\n        const target = parseTweetUrl(kwargs.url);\n        await page.goto(target.url);\n        await page.wait({ selector: '[data-testid=\"primaryColumn\"]' });\n        const result = await page.evaluate(`(async () => {\n        let writeStarted = false;\n        try {\n            ${buildTwitterArticleScopeSource(target.id)}\n            // Poll for the tweet to render. State probes scoped to the article\n            // matching the requested status id — bare querySelector on a\n            // conversation page would silently grab the first article (e.g.\n            // the parent tweet) and retweet the wrong one.\n            let attempts = 0;\n            let retweetBtn = null;\n            let unretweetBtn = null;\n            let targetArticle = null;\n\n            while (attempts < 20) {\n                targetArticle = findTargetArticle();","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/retweet.js#L1-L37","documentation":"The `twitter retweet` CLI command, like the reply command, requires an attached browser session. When page is undefined (no browser session), func throws this CommandExecutionError immediately, before parsing the tweet URL or navigating. Retweeting requires a logged-in browser context to click the retweet control.","triggerScenarios":"Invoking `twitter retweet <tweet-url>` without a browser session attached — no prior browser open/attach in the CLI session, or calling the retweet func directly with page undefined.","commonSituations":"Automations that call retweet before establishing the browser session; a crashed/closed automation browser dropping the session between commands; CI runs that skip the browser-attach step.","solutions":["Open/attach the browser session (and log in to X) before running `twitter retweet`.","Make sure the previous automation step did not close the browser or the profile.","In scripted/test usage, pass a valid page handle as the first argument to func."],"exampleFix":"// before\nopencli twitter retweet <tweet-url>            # no session\n// after\nopencli browser open --profile x-account\nopencli twitter retweet <tweet-url>","handlingStrategy":"validation","validationCode":"if (!session || !session.page) {\n  throw new Error('Open/attach a browser session before twitter retweet');\n}","typeGuard":"function hasBrowserSession(session) {\n  return !!session && typeof session === 'object' && !!session.page && typeof session.page.goto === 'function';\n}","tryCatchPattern":"try {\n  await cli('twitter', 'retweet', { url: tweetUrl });\n} catch (e) {\n  if (String(e.message) === 'Browser session required for twitter retweet') {\n    await cli('browser', 'open', { profile: 'x-account' });\n    await cli('twitter', 'retweet', { url: tweetUrl });\n  } else throw e;\n}","preventionTips":["Always attach the browser session before twitter retweet in scripts.","Assert the browser is still running between long-running automation steps.","Log in to the X account in the automation profile ahead of time."],"tags":["browser-session","prerequisite","twitter"],"backgroundTag":"missing-browser-session","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}