jackwener/OpenCLI · error · CommandExecutionError

Browser session required for instagram note

Error message

Browser session required for instagram note

What it means

requirePage guards every instagram note operation: posting a note is a browser-automation action that needs an active Puppeteer/Playwright page logged into Instagram. When page is null/undefined the CommandExecutionError 'Browser session required for instagram note' is thrown instead of dereferencing page and crashing with an opaque TypeError.

Source

Thrown at clis/instagram/note.js:9

import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
const INSTAGRAM_INBOX_URL = 'https://www.instagram.com/direct/inbox/';
const INSTAGRAM_NOTE_DOC_ID = '25155183657506484';
const INSTAGRAM_NOTE_MUTATION_NAME = 'usePolarisCreateInboxTrayItemSubmitMutation';
const INSTAGRAM_NOTE_ROOT_FIELD = 'xdt_create_inbox_tray_item';
function requirePage(page) {
    if (!page)
        throw new CommandExecutionError('Browser session required for instagram note');
    return page;
}
function validateInstagramNoteArgs(kwargs) {
    if (kwargs.content === undefined) {
        throw new ArgumentError('Argument "content" is required.', 'Provide a note text, for example: opencli instagram note "hello"');
    }
}
function normalizeInstagramNoteContent(kwargs) {
    const content = String(kwargs.content ?? '').trim();
    if (!content) {
        throw new ArgumentError('Instagram note content cannot be empty.', 'Provide a non-empty note text, for example: opencli instagram note "hello"');
    }
    if (Array.from(content).length > 60) {
        throw new ArgumentError('Instagram note content must be 60 characters or fewer.', 'Shorten the note text and try again.');
    }
    return content;
}
function buildNoteSuccessResult(noteId) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open a browser session (the CLI's browser/login command) before running instagram note
  2. Log in to Instagram in that session so the direct inbox page is accessible
  3. Check that the browser process is still alive; restart it if it crashed
  4. Handle CommandExecutionError in wrapper scripts and prompt the user to open a session first

Example fix

// before
await postInstagramNote(null, { content: 'hello' }); // throws
// after
const page = await getOrCreateBrowserPage(); // launches/logs in if needed
await postInstagramNote(requirePage(page), { content: 'hello' });
Defensive patterns

Strategy: try-catch

Validate before calling

if (!page) {
  throw new Error('Open a browser session and log in before running instagram note.');
}

Type guard

function hasActivePage(p) {
  return !!p && typeof p.goto === 'function' && !p.isClosed();
}

Try / catch

try {
  await instagramNote(ctx, { content: 'hello' });
} catch (e) {
  if (e.message === 'Browser session required for instagram note') {
    console.error('No browser session. Run the browser/login command first, then retry.');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the instagram note command without first opening a browser session (page === null), or after the browser/page was closed before requirePage(page) is invoked inside browserPage.

Common situations: Running the CLI headless-scripted without the login/browser step; browser crashed or was closed between commands; forgetting the command that establishes the session; env where browser launch silently failed.

Related errors


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