{"record":{"id":"8a157d98a94b24dd","repo":"jackwener/OpenCLI","slug":"browser-session-required-8a157d","errorCode":null,"errorMessage":"Browser session required","messagePattern":"Browser session required","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reddit/saved.js","lineNumber":17,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\ncli({\n    site: 'reddit',\n    name: 'saved',\n    access: 'read',\n    description: 'Browse your saved 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 + '/saved.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 || c.data.body?.slice(0, 100) || '',\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/saved.js#L1-L35","documentation":"The reddit `saved` command (listing saved posts) requires an authenticated browser `page` to fetch https://www.reddit.com and read the user's saved items. If no page is passed to `func` it throws this CommandExecutionError immediately. Like the save command, it cannot operate without an active browser session.","triggerScenarios":"Running the reddit saved command with no browser session attached — page is falsy when func is invoked, typically because no session was started or the session layer failed to provide a page.","commonSituations":"CI/headless environments where the browser never launched; forgetting to call the login/session-open command first; a crashed browser leaving the session handle null.","solutions":["Open and authenticate a browser session before running `reddit saved`","Check that the browser process is running and the page handle is valid","Ensure your runner passes the live page into the command's func","Handle CommandExecutionError by falling back to an explicit 'please log in' message"],"exampleFix":"// before\nconst items = await runCli(['reddit', 'saved', '--limit', '20']);\n// after\nif (!(await hasActiveSession())) await loginReddit();\nconst items = await runCli(['reddit', 'saved', '--limit', '20']);","handlingStrategy":"validation","validationCode":"// Ensure a live, logged-in page before listing saved posts:\nif (!page) throw new Error('Browser session required — run the login command first');","typeGuard":"function hasBrowserSession(page) {\n  return page != null && typeof page.goto === 'function' && typeof page.evaluate === 'function';\n}","tryCatchPattern":"try {\n  const saved = await runCli(['reddit', 'saved', '--limit', '20']);\n} catch (e) {\n  if (e.message === 'Browser session required') {\n    await startSessionAndLogin();\n    return runCli(['reddit', 'saved', '--limit', '20']);\n  }\n  throw e;\n}","preventionTips":["Open and authenticate the session before any saved-list command","Handle headless/CI environments by launching the browser explicitly","Fail fast with a clear message if the session handle is null"],"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"}