{"record":{"id":"abde4a8d8b54e74b","repo":"jackwener/OpenCLI","slug":"browser-session-required-abde4a","errorCode":null,"errorMessage":"Browser session required","messagePattern":"Browser session required","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reddit/upvote.js","lineNumber":18,"sourceCode":"import { CommandExecutionError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\ncli({\n    site: 'reddit',\n    name: 'upvote',\n    access: 'write',\n    description: 'Upvote or downvote a Reddit post',\n    domain: 'reddit.com',\n    strategy: Strategy.COOKIE,\n    browser: true,\n    args: [\n        { name: 'post-id', type: 'string', required: true, positional: true, help: 'Post ID (e.g. 1abc123) or fullname (t3_xxx)' },\n        { name: 'direction', type: 'string', default: 'up', help: 'Vote direction: up, down, none' },\n    ],\n    columns: ['status', 'message'],\n    func: async (page, kwargs) => {\n        if (!page)\n            throw new CommandExecutionError('Browser session required');\n        await page.goto('https://www.reddit.com');\n        const result = await page.evaluate(`(async () => {\n      try {\n        let postId = ${JSON.stringify(kwargs['post-id'])};\n        // Extract ID from URL if needed\n        const urlMatch = postId.match(/comments\\\\/([a-z0-9]+)/);\n        if (urlMatch) postId = urlMatch[1];\n        // Build fullname\n        const fullname = postId.startsWith('t3_') || postId.startsWith('t1_')\n          ? postId : 't3_' + postId;\n\n        const dir = ${JSON.stringify(kwargs.direction)};\n        const direction = dir === 'down' ? -1 : dir === 'none' ? 0 : 1;\n\n        // Get modhash from Reddit config\n        const configEl = document.getElementById('config');\n        let modhash = '';\n        if (configEl) {","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/upvote.js#L1-L36","documentation":"clis/reddit/upvote.js requires a connected browser page; its func receives `page` from the browser session bridge, and when it is falsy the command throws CommandExecutionError('Browser session required'). Voting on a post happens inside the logged-in Reddit page via page.evaluate, so without a live browser session the command cannot run. This is a precondition check, not an HTTP/auth failure.","triggerScenarios":"Running `reddit upvote <post-id>` without the browser daemon running, without the extension connected, or in an environment where the page handle was not provided to the command func.","commonSituations":"Forgot to start the browser daemon / launch Chrome before the CLI call; running in CI or headless shell with no Chrome attached; daemon crashed between commands; wrong profile flag disconnecting the session.","solutions":["Start the browser daemon / open the managed Chrome instance, then rerun the command.","Verify the extension is connected to the daemon (check daemon status command if available).","Ensure you invoke through the CLI entry point that injects `page`, not the func directly with no page.","Script-wise, check session availability first and start it automatically before calling the command."],"exampleFix":"// before\nawait run(['reddit', 'upvote', '1abc123']); // Browser session required\n// after\nif (!await isBrowserDaemonRunning()) await startBrowserDaemon();\nawait run(['reddit', 'upvote', '1abc123']);","handlingStrategy":"validation","validationCode":"import { execSync } from 'node:child_process';\n// before invoking the command, ensure the browser daemon is reachable\ntry { execSync('opencli browser status', { stdio: 'ignore' }); }\ncatch { throw new Error('Start the browser daemon / Chrome before running reddit upvote'); }","typeGuard":"function hasPage(x) { return x != null && typeof x.goto === 'function' && typeof x.evaluate === 'function'; }","tryCatchPattern":"try {\n  await run(['reddit', 'upvote', postId]);\n} catch (e) {\n  if (e.message === 'Browser session required') {\n    await startBrowserDaemon();\n    await run(['reddit', 'upvote', postId]); // retry once\n  } else throw e;\n}","preventionTips":["Start the browser daemon/Chrome before invoking reddit commands","Auto-start the session in scripts when missing","In CI, provide a headless Chrome attached to the daemon or skip browser commands","Always invoke via the CLI entry point that injects `page`"],"tags":["browser-session","prerequisite","reddit"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}