jackwener/OpenCLI · error · AuthRequiredError

Instagram login required before posting

Error message

Instagram login required before posting

What it means

ensureComposerOpen runs an in-page script (buildEnsureComposerOpenJs) that detects the Instagram login route or a visible username/password form plus a login button. When detected it returns {reason:'auth'} and the wrapper throws AuthRequiredError for www.instagram.com, meaning the stored session cookie is missing or expired and posting cannot proceed.

Solutions

  1. Run the Instagram login flow for this CLI first to establish a session, then retry the post
  2. Persist and reuse the browser profile/cookies between runs so the session survives
  3. Log in manually in the automation browser if challenged, complete any 2FA/verification, then retry
  4. If cookies are supplied externally, refresh them from a logged-in browser session
  5. Check Instagram account security emails — a forced logout invalidates stored sessions

Example fix

// before
await executeUiInstagramPost(kwargs); // fresh profile, not logged in -> AuthRequiredError
// after
await cli.instagram.login({ headless: false }); // establish session first
await executeUiInstagramPost(kwargs);
Defensive patterns

Strategy: try-catch

Validate before calling

// Check the session is alive before posting
const page = await getSessionPage();
await page.goto('https://www.instagram.com/', { waitUntil: 'networkidle' });
if (/\/accounts\/login/.test(new URL(page.url()).pathname)) {
  throw new Error('Instagram session expired — log in first');
}

Type guard

function isAuthRequiredError(e) {
  return e instanceof Error && (e.name === 'AuthRequiredError'
    || /login required/i.test(e.message));
}

Try / catch

try {
  await executeUiInstagramPost(kwargs);
} catch (e) {
  if (isAuthRequiredError(e)) {
    await runInstagramLogin(); // interactive login / refresh cookies
    await executeUiInstagramPost(kwargs);
  } else throw e;
}

Prevention

When it happens

Trigger: Executing the post command without a prior Instagram login; the session cookie expired or was invalidated (password change, logout elsewhere, Instagram security challenge); the page redirected to /accounts/login; the automation browser profile is fresh.

Common situations: Long-lived CI sessions whose cookies expired; logging into the account from another device forcing session invalidation; running with a cleaned/temporary browser profile; Instagram detecting automation and forcing re-authentication.

Related errors


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

Appendix: source

Thrown at clis/instagram/post.js:314

                    resetWindow = true;
                }
                catch {
                    // Best-effort: a fresh automation window is safer than reusing a polluted one.
                }
            }
            if (!resetWindow) {
                await dismissResidualDialogs(input.page);
                await input.page.wait({ time: 1 });
            }
        }
    }
    throw lastError instanceof Error ? lastError : new CommandExecutionError('Instagram post failed');
}
async function ensureComposerOpen(page) {
    const result = await page.evaluate(buildEnsureComposerOpenJs());
    if (!result?.ok) {
        if (result?.reason === 'auth')
            throw new AuthRequiredError('www.instagram.com', 'Instagram login required before posting');
        throw new CommandExecutionError('Failed to open Instagram post composer');
    }
}
async function dismissResidualDialogs(page) {
    for (let attempt = 0; attempt < 4; attempt++) {
        const result = await page.evaluate(`
      (() => {
        const isVisible = (el) => {
          if (!(el instanceof HTMLElement)) return false;
          const style = window.getComputedStyle(el);
          const rect = el.getBoundingClientRect();
          return style.display !== 'none'
            && style.visibility !== 'hidden'
            && rect.width > 0
            && rect.height > 0;
        };

        const dialogs = Array.from(document.querySelectorAll('[role="dialog"]'))

View on GitHub (pinned to 49907e53dc)