{"record":{"id":"ca74b25609356eeb","repo":"jackwener/OpenCLI","slug":"browser-session-required-ca74b2","errorCode":null,"errorMessage":"Browser session required","messagePattern":"Browser session required","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reddit/upvoted.js","lineNumber":17,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\ncli({\n    site: 'reddit',\n    name: 'upvoted',\n    access: 'read',\n    description: 'Browse your upvoted Reddit posts',\n    domain: 'reddit.com',\n    strategy: Strategy.COOKIE,\n    browser: true,\n    args: [\n        { name: 'limit', type: 'int', default: 15 },\n    ],\n    columns: ['title', 'subreddit', 'score', 'comments', 'url'],\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        // Get current username\n        const meRes = await fetch('/api/me.json?raw_json=1', { credentials: 'include' });\n        const me = await meRes.json();\n        const username = me?.name || me?.data?.name;\n        if (!username) return { error: 'Not logged in — cannot determine username' };\n\n        const limit = ${kwargs.limit};\n        const res = await fetch('/user/' + username + '/upvoted.json?limit=' + limit + '&raw_json=1', {\n          credentials: 'include'\n        });\n        const d = await res.json();\n        return (d?.data?.children || []).map(c => ({\n          title: c.data.title || '',\n          subreddit: c.data.subreddit_name_prefixed || 'r/' + (c.data.subreddit || '?'),\n          score: c.data.score || 0,","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/upvoted.js#L1-L35","documentation":"clis/reddit/upvoted.js throws CommandExecutionError('Browser session required') when the `page` argument injected into its func is falsy. Listing upvoted posts requires executing fetches inside the logged-in Reddit page via page.evaluate, so a live browser session is a hard prerequisite. The check happens before any navigation, at upvoted.js:17.","triggerScenarios":"Calling `reddit upvoted` with the browser daemon not running, the extension not connected, or the page handle missing (e.g. invoking the command func directly without a session).","commonSituations":"Daemon not started or crashed; running on a machine/container without Chrome; extension disconnected after browser restart; calling the internal func in tests without providing a page stub.","solutions":["Launch the managed Chrome/daemon and reconnect the extension, then rerun.","Check daemon/browser connect status before batch-running commands.","When calling func programmatically, pass a valid page object (real session or mock).","Wrap calls to catch this error and auto-start the session, then retry once."],"exampleFix":"// before\nconst posts = await upvotedFunc(undefined, { limit: 15 }); // throws\n// after\nconst page = await browser.getPage();\nif (!page) throw new Error('start the browser daemon first');\nconst posts = await upvotedFunc(page, { limit: 15 });","handlingStrategy":"validation","validationCode":"if (!(await browser.isConnected())) {\n  await browser.start(); // ensure daemon + extension before listing upvoted posts\n}","typeGuard":"function hasPage(x) { return x != null && typeof x.goto === 'function' && typeof x.evaluate === 'function'; }","tryCatchPattern":"try {\n  const posts = await run(['reddit', 'upvoted']);\n} catch (e) {\n  if (e.message === 'Browser session required') {\n    await browser.start();\n    return await run(['reddit', 'upvoted']);\n  }\n  throw e;\n}","preventionTips":["Check browser/daemon connectivity as a preflight step","Do not call the command func directly without a page in tests — stub one","Restart and reconnect the extension after browser crashes","Run browser-dependent commands only on machines with Chrome available"],"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"}