jackwener/OpenCLI · error · CommandExecutionError
Browser session required
Error message
Browser session required
What it means
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.
Source
Thrown at clis/reddit/subscribe.js:18
import { CommandExecutionError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
cli({
site: 'reddit',
name: 'subscribe',
access: 'write',
description: 'Subscribe or unsubscribe to a subreddit',
domain: 'reddit.com',
strategy: Strategy.COOKIE,
browser: true,
args: [
{ name: 'subreddit', type: 'string', required: true, positional: true, help: 'Subreddit name (e.g. python)' },
{ name: 'undo', type: 'boolean', default: false, help: 'Unsubscribe instead of subscribe' },
],
columns: ['status', 'message'],
func: async (page, kwargs) => {
if (!page)
throw new CommandExecutionError('Browser session required');
await page.goto('https://www.reddit.com');
const result = await page.evaluate(`(async () => {
try {
let sub = ${JSON.stringify(kwargs.subreddit)};
if (sub.startsWith('r/')) sub = sub.slice(2);
const undo = ${kwargs.undo ? 'true' : 'false'};
const action = undo ? 'unsub' : 'sub';
// Get modhash
const meRes = await fetch('/api/me.json', { credentials: 'include' });
const me = await meRes.json();
const modhash = me?.data?.modhash || '';
const res = await fetch('/api/subscribe', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
await redditSubscribe(page = null, { subreddit: 'python' }) // throws
// after
const page = await browser.newPage();
await loginReddit(page);
await redditSubscribe(page, { subreddit: 'python' }); Defensive patterns
Strategy: validation
Validate before calling
if (!page || typeof page.goto !== 'function') throw new Error('subscribe requires an active browser page'); Type guard
function hasBrowserPage(p){ return !!p && typeof p.goto === 'function' && typeof p.evaluate === 'function'; } Try / catch
try { await cli.redditSubscribe(sub); }
catch (e) { if (e.message === 'Browser session required') { await launchAndLoginBrowser(); return cli.redditSubscribe(sub); } throw e; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Browser session required
- reddit.com: ${result.detail}
- reddit.com
- Browser session required for bilibili subtitle
- Browser session required for bilibili summary
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/54e052591b2253e3.
Report an issue: GitHub.