jackwener/OpenCLI · error · CommandExecutionError

Browser session required for twitter quote

Error message

Browser session required for twitter quote

What it means

CommandExecutionError thrown at the top of the twitter quote command when the `page` argument is falsy — the command requires an active browser session but none was provided or the browser session was not started. All twitter commands of this style are browser-driven and cannot run without a live page.

Source

Thrown at clis/twitter/quote.js:125

cli({
    site: 'twitter',
    name: 'quote',
    access: 'write',
    description: 'Quote-tweet a specific tweet with your own text, optionally with a local or remote image',
    domain: 'x.com',
    strategy: Strategy.UI,
    browser: true,
    args: [
        { name: 'url', type: 'string', required: true, positional: true, help: 'The URL of the tweet to quote' },
        { name: 'text', type: 'string', required: true, positional: true, help: 'The text content of your quote' },
        { name: 'image', help: 'Optional local image path to attach to the quote tweet' },
        { name: 'image-url', help: 'Optional remote image URL to download and attach to the quote tweet' },
    ],
    columns: ['status', 'message', 'text'],
    func: async (page, kwargs) => {
        if (!page)
            throw new CommandExecutionError('Browser session required for twitter quote');
        if (kwargs.image && kwargs['image-url']) {
            throw new CommandExecutionError('Use either --image or --image-url, not both.');
        }

        // Validate URL (typed ArgumentError on malformed/off-domain inputs)
        // before any browser interaction or remote image download.
        const target = parseTweetUrl(kwargs.url);

        let localImagePath;
        let cleanupDir;
        try {
            if (kwargs.image) {
                localImagePath = resolveImagePath(kwargs.image);
            } else if (kwargs['image-url']) {
                const downloaded = await downloadRemoteImage(kwargs['image-url']);
                localImagePath = downloaded.absPath;
                cleanupDir = downloaded.cleanupDir;
            }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Start the browser session (e.g. run the browser open/start command) before invoking twitter quote
  2. Check that the previous step did not close the browser; keep the session alive across commands
  3. Guard programmatically: verify the page/session exists before calling the command
  4. Catch CommandExecutionError with the 'Browser session required' message and auto-start the browser then retry once

Example fix

// before
await cli.run('twitter quote', kwargs); // no browser open
// after
await cli.run('browser open'); // ensure session
await cli.run('twitter quote', kwargs);
Defensive patterns

Strategy: validation

Validate before calling

if (!browserSession || !browserSession.page) {
  await cli.run('browser open');
}

Type guard

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

Try / catch

try {
  await cli.run('twitter quote', kwargs);
} catch (e) {
  if (e instanceof CommandExecutionError && /Browser session required/.test(e.message)) {
    await cli.run('browser open');
    return cli.run('twitter quote', kwargs);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the 'twitter quote' command without first launching/connecting the browser so func receives page === undefined/null.

Common situations: Forgetting to open the browser session before running the command; session crashed or was closed mid-run; running in a headless pipeline where the browser bootstrap step was skipped or failed; invoking the command programmatically without the page argument.

Related errors


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