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.
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)
Solutions
- Run the Instagram login flow for this CLI first to establish a session, then retry the post
- Persist and reuse the browser profile/cookies between runs so the session survives
- Log in manually in the automation browser if challenged, complete any 2FA/verification, then retry
- If cookies are supplied externally, refresh them from a logged-in browser session
- 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
- Persist the browser profile so cookies survive across runs
- Re-authenticate proactively before long CI jobs (cookies expire within weeks)
- Never share one account session across many parallel automation runs
- Handle Instagram security challenges/2FA promptly — they invalidate stored sessions
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
- 请先在共享 Chrome 完成 1688 登录/验证,再重试(${action})
- Bilibili ${label} API requires login or permission: ${messag
- bilibili.com
- ${probe.detail}
- result.detail (auth required from Claude probe)
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/17dfd37908ea95ca.
Report an issue: GitHub.