{"record":{"id":"54e052591b2253e3","repo":"jackwener/OpenCLI","slug":"browser-session-required-54e052","errorCode":null,"errorMessage":"Browser session required","messagePattern":"Browser session required","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reddit/subscribe.js","lineNumber":18,"sourceCode":"import { CommandExecutionError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\ncli({\n    site: 'reddit',\n    name: 'subscribe',\n    access: 'write',\n    description: 'Subscribe or unsubscribe to a subreddit',\n    domain: 'reddit.com',\n    strategy: Strategy.COOKIE,\n    browser: true,\n    args: [\n        { name: 'subreddit', type: 'string', required: true, positional: true, help: 'Subreddit name (e.g. python)' },\n        { name: 'undo', type: 'boolean', default: false, help: 'Unsubscribe instead of subscribe' },\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 sub = ${JSON.stringify(kwargs.subreddit)};\n        if (sub.startsWith('r/')) sub = sub.slice(2);\n\n        const undo = ${kwargs.undo ? 'true' : 'false'};\n        const action = undo ? 'unsub' : 'sub';\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/subscribe', {\n          method: 'POST',\n          credentials: 'include',\n          headers: { 'Content-Type': 'application/x-www-form-urlencoded' },","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/subscribe.js#L1-L36","documentation":"CommandExecutionError thrown when the reddit subscribe command is invoked without an active browser session. The command uses Strategy.COOKIE with browser:true, so it needs a logged-in browser page to run the /api/subscribe POST; without one, it fails fast instead of silently no-op'ing a write action.","triggerScenarios":"Calling the subscribe command (subscribe/undo to a subreddit) in an environment where the browser-session-backed `page` argument is null/undefined — e.g. headless/no-browser mode, browser not launched, or calling func directly with page=null.","commonSituations":"Running the CLI in CI without a browser configured; browser login to reddit.com not completed; a wrapper invoking the command function with no page handle; browser launch failure upstream.","solutions":["Launch the command in browser mode so a page handle is created (per the library's browser:true config)","Log into reddit.com in that browser session first — subscribe is a write action requiring cookies","If embedding, pass a valid Playwright/puppeteer page object instead of null/undefined","Check that the browser runtime (Chromium etc.) is installed and the library can launch it"],"exampleFix":"// before\nawait redditSubscribe(page = null, { subreddit: 'python' }) // throws\n// after\nconst page = await browser.newPage();\nawait loginReddit(page);\nawait redditSubscribe(page, { subreddit: 'python' });","handlingStrategy":"validation","validationCode":"if (!page || typeof page.goto !== 'function') throw new Error('subscribe requires an active browser page');","typeGuard":"function hasBrowserPage(p){ return !!p && typeof p.goto === 'function' && typeof p.evaluate === 'function'; }","tryCatchPattern":"try { await cli.redditSubscribe(sub); }\ncatch (e) { if (e.message === 'Browser session required') { await launchAndLoginBrowser(); return cli.redditSubscribe(sub); } throw e; }","preventionTips":["Always run browser:true commands in browser mode with a logged-in session","Verify the browser runtime is installed in CI images","When embedding, pass a real page object — never null","Log into reddit.com before any write (subscribe) operation"],"tags":["reddit","browser-session","authentication","write-operation"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}