jackwener/OpenCLI · error · CommandExecutionError

Browser session required

Error message

Browser session required

What it means

clis/reddit/upvote.js requires a connected browser page; its func receives `page` from the browser session bridge, and when it is falsy the command throws CommandExecutionError('Browser session required'). Voting on a post happens inside the logged-in Reddit page via page.evaluate, so without a live browser session the command cannot run. This is a precondition check, not an HTTP/auth failure.

Source

Thrown at clis/reddit/upvote.js:18

import { CommandExecutionError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
cli({
    site: 'reddit',
    name: 'upvote',
    access: 'write',
    description: 'Upvote or downvote a Reddit post',
    domain: 'reddit.com',
    strategy: Strategy.COOKIE,
    browser: true,
    args: [
        { name: 'post-id', type: 'string', required: true, positional: true, help: 'Post ID (e.g. 1abc123) or fullname (t3_xxx)' },
        { name: 'direction', type: 'string', default: 'up', help: 'Vote direction: up, down, none' },
    ],
    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 postId = ${JSON.stringify(kwargs['post-id'])};
        // Extract ID from URL if needed
        const urlMatch = postId.match(/comments\\/([a-z0-9]+)/);
        if (urlMatch) postId = urlMatch[1];
        // Build fullname
        const fullname = postId.startsWith('t3_') || postId.startsWith('t1_')
          ? postId : 't3_' + postId;

        const dir = ${JSON.stringify(kwargs.direction)};
        const direction = dir === 'down' ? -1 : dir === 'none' ? 0 : 1;

        // Get modhash from Reddit config
        const configEl = document.getElementById('config');
        let modhash = '';
        if (configEl) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Start the browser daemon / open the managed Chrome instance, then rerun the command.
  2. Verify the extension is connected to the daemon (check daemon status command if available).
  3. Ensure you invoke through the CLI entry point that injects `page`, not the func directly with no page.
  4. Script-wise, check session availability first and start it automatically before calling the command.

Example fix

// before
await run(['reddit', 'upvote', '1abc123']); // Browser session required
// after
if (!await isBrowserDaemonRunning()) await startBrowserDaemon();
await run(['reddit', 'upvote', '1abc123']);
Defensive patterns

Strategy: validation

Validate before calling

import { execSync } from 'node:child_process';
// before invoking the command, ensure the browser daemon is reachable
try { execSync('opencli browser status', { stdio: 'ignore' }); }
catch { throw new Error('Start the browser daemon / Chrome before running reddit upvote'); }

Type guard

function hasPage(x) { return x != null && typeof x.goto === 'function' && typeof x.evaluate === 'function'; }

Try / catch

try {
  await run(['reddit', 'upvote', postId]);
} catch (e) {
  if (e.message === 'Browser session required') {
    await startBrowserDaemon();
    await run(['reddit', 'upvote', postId]); // retry once
  } else throw e;
}

Prevention

When it happens

Trigger: Running `reddit upvote <post-id>` without the browser daemon running, without the extension connected, or in an environment where the page handle was not provided to the command func.

Common situations: Forgot to start the browser daemon / launch Chrome before the CLI call; running in CI or headless shell with no Chrome attached; daemon crashed between commands; wrong profile flag disconnecting the session.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/abde4a8d8b54e74b. Report an issue: GitHub.