jackwener/OpenCLI · error · CommandExecutionError

Browser session required for instagram story

Error message

Browser session required for instagram story

What it means

A CommandExecutionError thrown by requirePage() in clis/instagram/story.js when no active browser (Puppeteer/Playwright) page is available. Posting a story requires a real logged-in browser session; the headless-fetch path used by other subcommands is not sufficient.

Source

Thrown at clis/instagram/story.js:12

import * as fs from 'node:fs';
import * as path from 'node:path';
import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
import { publishStoryViaPrivateApi, resolveInstagramPrivatePublishConfig, } from './_shared/private-publish.js';
import { resolveCurrentUserId, resolveInstagramRuntimeInfo } from './_shared/runtime-info.js';
import { INSTAGRAM_HOME_URL } from './_shared/navigation.js';
const SUPPORTED_STORY_IMAGE_EXTENSIONS = new Set(['.jpg', '.jpeg', '.png', '.webp']);
const SUPPORTED_STORY_VIDEO_EXTENSIONS = new Set(['.mp4']);
function requirePage(page) {
    if (!page)
        throw new CommandExecutionError('Browser session required for instagram story');
    return page;
}
function validateInstagramStoryArgs(kwargs) {
    if (kwargs.media === undefined) {
        throw new ArgumentError('Argument "media" is required.', 'Provide --media /path/to/file.jpg or --media /path/to/file.mp4');
    }
}
function normalizeStoryMediaItem(kwargs) {
    const raw = String(kwargs.media ?? '').trim();
    const parts = raw.split(',').map((part) => part.trim()).filter(Boolean);
    if (parts.length === 0) {
        throw new ArgumentError('Argument "media" is required.', 'Provide --media /path/to/file.jpg or --media /path/to/file.mp4');
    }
    if (parts.length > 1) {
        throw new ArgumentError('Instagram story currently supports a single media item.', 'Provide one image or one video path with --media');
    }
    const resolved = path.resolve(parts[0]);
    if (!fs.existsSync(resolved)) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Start an authenticated browser session (e.g. run the login command) before invoking the story command
  2. Check that the browser process is still running and the page handle is alive
  3. In code, create/open the page (browser.newPage()) and pass it to the story command
  4. Guard calls: if (!page) await openSession() before calling story functions

Example fix

// before
await postStory({ media: 'photo.jpg' }); // page is undefined
// after
const page = await getSessionPage(); // launches/logs in if needed
await postStory({ page, media: 'photo.jpg' });
Defensive patterns

Strategy: validation

Validate before calling

if (!page || typeof page.evaluate !== 'function') {
  throw new Error('Open an authenticated browser session before running the story command');
}

Type guard

function isPage(p) { return !!p && typeof p.evaluate === 'function' && typeof p.goto === 'function'; }

Try / catch

try {
  await postStory({ page, media: file });
} catch (e) {
  if (/Browser session required/.test(e.message)) {
    page = await launchAndLogin();
    await postStory({ page, media: file });
  } else throw e;
}

Prevention

When it happens

Trigger: registerThreadQuery calls requirePage(page) and page is undefined/null — i.e. the story command was invoked without first starting an authenticated browser session.

Common situations: Running `instagram story` before `instagram login`/browser launch, a crashed or closed browser, or programmatic use where the page handle was never created or was closed.

Related errors


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