{"record":{"id":"8398f3bef89f3cd5","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-twitter-unblock","errorCode":null,"errorMessage":"Browser session required for twitter unblock","messagePattern":"Browser session required for twitter unblock","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/unblock.js","lineNumber":17,"sourceCode":"import { CommandExecutionError, TimeoutError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\ncli({\n    site: 'twitter',\n    name: 'unblock',\n    access: 'write',\n    description: 'Unblock a Twitter user',\n    domain: 'x.com',\n    strategy: Strategy.UI,\n    browser: true,\n    args: [\n        { name: 'username', type: 'string', positional: true, required: true, help: 'Twitter screen name (without @)' },\n    ],\n    columns: ['status', 'message'],\n    func: async (page, kwargs) => {\n        if (!page)\n            throw new CommandExecutionError('Browser session required for twitter unblock');\n        const username = kwargs.username.replace(/^@/, '');\n        await page.goto(`https://x.com/${username}`);\n        await page.wait({ selector: '[data-testid=\"primaryColumn\"]' });\n        const result = await page.evaluate(`(async () => {\n        let writeStarted = false;\n        try {\n            let attempts = 0;\n            let unblockBtn = null;\n            const getPrimary = () => document.querySelector('[data-testid=\"primaryColumn\"]');\n            if (!getPrimary()) {\n                return { ok: false, message: 'Could not find profile surface. Are you logged in?' };\n            }\n\n            while (attempts < 20) {\n                const primary = getPrimary();\n                if (!primary) {\n                    return { ok: false, message: 'Could not find profile surface. Are you logged in?' };\n                }","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/unblock.js#L1-L35","documentation":"CommandExecutionError (code COMMAND_EXEC) thrown by `twitter unblock` because the command is a browser-write command: it requires an interactive Playwright/CDP page attached to the logged-in X session. When `page` is null the library refuses to attempt the write via the API-only path. It fails fast rather than silently doing nothing.","triggerScenarios":"Running `twitter unblock <username>` without an active browser session (e.g. headless/API mode, or before connecting a Chrome session), so `func` receives page === null/undefined.","commonSituations":"Scripting the CLI without launching/connecting the browser; running in CI where no logged-in Chrome exists; forgetting the login/bootstrap step for x.com in the current profile.","solutions":["Start/connect a browser session first (the CLI's browser login/connect flow for x.com) and ensure you are logged in, then re-run `twitter unblock`","Run the command in interactive mode rather than a mode that passes no page","In scripts, check browser availability before invoking the command and fail with a clear message"],"exampleFix":"// before\nawait cli.run(['twitter', 'unblock', 'user']); // no browser session\n// after\nconst page = await getBrowserPage('x.com'); // connect logged-in session first\nif (!page) throw new Error('Start a browser session and log in to x.com first');\nawait cli.run(['twitter', 'unblock', 'user']);","handlingStrategy":"validation","validationCode":"if (!browserSession || !browserSession.page) {\n  throw new Error('Start a browser session and log in to x.com before running twitter write commands');\n}","typeGuard":"function hasBrowserPage(ctx) { return ctx != null && typeof ctx.page === 'object' && ctx.page !== null; }","tryCatchPattern":"try {\n  await cli.run(['twitter', 'unblock', user]);\n} catch (e) {\n  if (e.code === 'COMMAND_EXEC' && /Browser session required/.test(e.message)) {\n    console.error('Connect a browser session and log in to x.com first');\n  } else throw e;\n}","preventionTips":["Always bootstrap the browser session (connect Chrome, log in to x.com) before write commands","Group write commands in scripts after a single verified login step","Add a session preflight check in CI wrappers and skip browser-only commands when absent","Never run twitter write commands in headless/API-only mode"],"tags":["twitter","browser-session","precondition","write-command"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}