{"record":{"id":"93d97b9e227c55b9","repo":"jackwener/OpenCLI","slug":"browser-session-required-93d97b","errorCode":null,"errorMessage":"Browser session required","messagePattern":"Browser session required","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reddit/comment.js","lineNumber":18,"sourceCode":"import { CommandExecutionError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\ncli({\n    site: 'reddit',\n    name: 'comment',\n    access: 'write',\n    description: 'Post a comment on 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: 'text', type: 'string', required: true, positional: true, help: 'Comment text' },\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        const urlMatch = postId.match(/comments\\\\/([a-z0-9]+)/);\n        if (urlMatch) postId = urlMatch[1];\n        const fullname = postId.startsWith('t3_') || postId.startsWith('t1_')\n          ? postId : 't3_' + postId;\n\n        const text = ${JSON.stringify(kwargs.text)};\n\n        // Get modhash\n        const meRes = await fetch('/api/me.json', { credentials: 'include' });\n        const me = await meRes.json();\n        const modhash = me?.data?.modhash || '';\n\n        const res = await fetch('/api/comment', {\n          method: 'POST',","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/comment.js#L1-L36","documentation":"CommandExecutionError thrown by the `reddit comment` command when it is invoked without an active browser session: the func receives page === null. Commenting requires a logged-in, cookie-backed browser context on reddit.com, so the command refuses to run without one.","triggerScenarios":"Calling the comment command in a non-browser context or before any login/session is established — the registry invokes func with page=null (e.g. no `--browser`/no persisted session), and the guard `if (!page) throw` fires.","commonSituations":"Running the command in a fresh environment with no browser profile; scripting the CLI without first running the reddit login; a configuration change that disables the browser strategy for the command.","solutions":["Run the reddit login flow first so a browser session exists, then retry the comment command.","Ensure the command is invoked with the browser/browser-session option enabled (the command requires browser: true).","Verify the persisted browser profile path exists and is writable so the session can be restored.","If scripting, establish the session programmatically before calling comment instead of calling it cold."],"exampleFix":"// before: cold call, page is null\nopencli reddit comment 1abc123 \"nice post\"\n// after: authenticate first\nopencli reddit login && opencli reddit comment 1abc123 \"nice post\"","handlingStrategy":"validation","validationCode":"if (!page || page.isClosed?.()) {\n  throw new Error('Run `reddit login` to establish a browser session before commenting.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await opencli.reddit.comment(postId, text);\n} catch (e) {\n  if (/Browser session required/.test(e.message)) {\n    await opencli.reddit.login();\n    return opencli.reddit.comment(postId, text);\n  }\n  throw e;\n}","preventionTips":["Run the reddit login flow before browser-required commands in scripts/CI.","Cache the browser profile so sessions persist between invocations.","Don't disable the browser strategy for commands that need one.","Check page availability before invoking write-style commands."],"tags":["auth","reddit","browser","prerequisite"],"backgroundTag":"missing-session-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}