{"record":{"id":"3436b95db62a91e4","repo":"jackwener/OpenCLI","slug":"browser-session-required-3436b9","errorCode":null,"errorMessage":"Browser session required","messagePattern":"Browser session required","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reddit/save.js","lineNumber":18,"sourceCode":"import { CommandExecutionError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\ncli({\n    site: 'reddit',\n    name: 'save',\n    access: 'write',\n    description: 'Save or unsave 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: 'undo', type: 'boolean', default: false, help: 'Unsave instead of save' },\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 undo = ${kwargs.undo ? 'true' : 'false'};\n        const endpoint = undo ? '/api/unsave' : '/api/save';\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(endpoint, {","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/save.js#L1-L36","documentation":"The reddit `save` CLI command requires an active browser session (a logged-in Playwright-style `page`) to operate on reddit.com. When the `func` receives no page object it throws this CommandExecutionError instead of silently failing on page.goto. It means the command was invoked outside a browser session context.","triggerScenarios":"Running the reddit save command without first starting/attaching a browser session, e.g. invoking the CLI in a mode where the page argument is undefined, or the browser failed to launch/attach before the command ran.","commonSituations":"Running commands via a script that skips the browser bootstrap; browser launch failure upstream that left page null; invoking the command headlessly without the session plugin enabled.","solutions":["Start a browser session (login) before running the reddit save command","Verify the browser launched successfully and check earlier logs for launch errors","Ensure the command is invoked through the path that injects the `page` argument into `func`","Catch CommandExecutionError and prompt the user to open a browser session first"],"exampleFix":"// before\nawait runCli(['reddit', 'save', postId]);\n// after\nconst page = await openBrowserSession();\nif (!page) throw new Error('Start a browser session first');\nawait runCli(['reddit', 'save', postId], { page });","handlingStrategy":"validation","validationCode":"// Check before invoking the command:\nif (!page) throw new Error('Open a browser session (login) before running reddit save');","typeGuard":"function hasBrowserSession(page) {\n  return page != null && typeof page.goto === 'function' && typeof page.evaluate === 'function';\n}","tryCatchPattern":"try {\n  await runCli(['reddit', 'save', postId]);\n} catch (e) {\n  if (e.message === 'Browser session required') {\n    await startSessionAndLogin();\n    await runCli(['reddit', 'save', postId]);\n  } else throw e;\n}","preventionTips":["Always bootstrap the browser session before reddit commands","Verify the browser launched successfully in startup logs","In scripts, assert session existence before the command loop"],"tags":["browser-session","reddit","prerequisite"],"backgroundTag":"missing-browser-session","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}