{"record":{"id":"248cda5a5069f565","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-twitter-like","errorCode":null,"errorMessage":"Browser session required for twitter like","messagePattern":"Browser session required for twitter like","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/like.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: 'like',\n    access: 'write',\n    description: 'Like a specific tweet',\n    domain: 'x.com',\n    strategy: Strategy.UI, // Utilizes internal DOM flows for interaction\n    browser: true,\n    args: [\n        { name: 'url', type: 'string', required: true, positional: true, help: 'The URL of the tweet to like' },\n    ],\n    columns: ['status', 'message'],\n    func: async (page, kwargs) => {\n        if (!page)\n            throw new CommandExecutionError('Browser session required for twitter like');\n        const target = parseTweetUrl(kwargs.url);\n        await page.goto(target.url);\n        await page.wait({ selector: '[data-testid=\"primaryColumn\"]' }); // Wait for tweet to load completely\n        const result = await page.evaluate(`(async () => {\n        let writeStarted = false;\n        try {\n            ${buildTwitterArticleScopeSource(target.id)}\n            // Poll for the tweet to render. We scope state probes to the\n            // article matching the requested status id — on conversation\n            // pages multiple articles render and a bare querySelector would\n            // grab the first one (silent: like the wrong tweet).\n            let attempts = 0;\n            let likeBtn = null;\n            let unlikeBtn = 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/like.js#L1-L37","documentation":"The twitter like CLI requires an active browser session (a logged-in page handle). When the `page` argument is falsy, the command cannot interact with Twitter, so it immediately throws this CommandExecutionError instead of proceeding to parse the tweet URL. It is a precondition check, thrown before any navigation happens.","triggerScenarios":"Calling the `twitter like` command (or its exported func) without a connected browser session — i.e. `page` is null/undefined because no browser was launched or the session was not attached before invoking the command.","commonSituations":"Running the CLI outside a browser-session context (missing `--browser`/session attach flag or not calling the session-open command first); programmatically invoking the command's func with no page handle; the browser crashed or was closed earlier in a script so the page handle became null.","solutions":["Open/attach a browser session before running the command (e.g. run the session/auth command first, or pass the browser/session flag)","If scripting, pass the page handle into the command's func","Check that the browser did not crash or exit earlier in the pipeline","Verify the CLI invocation includes the required browser-session options per the library docs"],"exampleFix":"// before\nawait clis.twitter.like.func(null, { url: tweetUrl });\n// after\nconst page = await session.open(); // ensure logged-in browser session\nawait clis.twitter.like.func(page, { url: tweetUrl });","handlingStrategy":"validation","validationCode":"if (!page) throw new Error('twitter like requires an open browser session — call session.open() first');","typeGuard":"function hasPage(p) { return p != null && typeof p === 'object' && typeof p.goto === 'function'; }","tryCatchPattern":"try {\n  await clis.twitter.like.func(page, { url });\n} catch (e) {\n  if (e.message.startsWith('Browser session required')) {\n    page = await session.open();\n    return clis.twitter.like.func(page, { url });\n  }\n  throw e;\n}","preventionTips":["Always open/attach the browser session before invoking twitter commands","In scripts, pass the page handle explicitly to command funcs","Check the session is still alive (browser not closed/crashed) before each command","Wrap long pipelines to re-open the session if it drops"],"tags":["twitter","browser-session","precondition"],"backgroundTag":"missing-browser-session","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}