jackwener/OpenCLI · error · CommandExecutionError

Failed to open Instagram post composer

Error message

Failed to open Instagram post composer

What it means

If ensureComposerOpen's in-page probe fails for any reason other than auth (result.ok is falsy without reason==='auth'), a generic CommandExecutionError 'Failed to open Instagram post composer' is thrown. Note the probe script returns {ok:true} as a fallback when it cannot find the Create button and no file input exists, so a hard failure typically means page.evaluate itself threw (navigation race, detached context) or result was unexpectedly null.

Source

Thrown at clis/instagram/post.js:315

                }
                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"]'))
          .filter((el) => el instanceof HTMLElement && isVisible(el));

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the command — composer-open failures are frequently transient; add backoff
  2. Ensure the page is fully loaded and on instagram.com before ensureComposerOpen runs (gotoInstagramHome + waitForSelector on a stable element)
  3. Capture a screenshot/HTML dump on failure to diagnose the actual page state
  4. Update the probe selectors if Instagram changed its DOM; pin a stable layout where possible
  5. Verify the browser session is alive (not crashed/closed) before evaluating

Example fix

// before
await ensureComposerOpen(page); // throws if evaluate races navigation
// after
await page.gotoInstagramHome();
await page.waitForSelector('main', { timeout: 30000 });
for (let i = 0; i < 3; i++) {
  try { await ensureComposerOpen(page); break; }
  catch (e) {
    if (i === 2 || e instanceof AuthRequiredError) throw e;
    await page.waitForTimeout(2000);
  }
}
Defensive patterns

Strategy: retry

Validate before calling

// Ensure page readiness before opening the composer
await page.goto('https://www.instagram.com/', { waitUntil: 'networkidle' });
await page.waitForSelector('main', { timeout: 30000 });
if (page.isClosed()) throw new Error('Browser page is closed');

Type guard

function isComposerOpenFailure(e) {
  return e instanceof Error
    && !(e.name === 'AuthRequiredError')
    && /failed to open instagram post composer/i.test(e.message);
}

Try / catch

for (let attempt = 1; attempt <= 3; attempt++) {
  try { await executeUiInstagramPost(kwargs); break; }
  catch (e) {
    if (isAuthRequiredError(e) || attempt === 3) throw e;
    await new Promise(r => setTimeout(r, 2000 * attempt));
  }
}

Prevention

When it happens

Trigger: page.evaluate throwing because the page navigated mid-evaluation or the tab crashed/closed; result being null/undefined due to an interrupted evaluation; Instagram DOM changes that make the probe return a non-ok payload; slow page load leaving the app in a broken intermediate state.

Common situations: Flaky network or Instagram slowness during automation runs; the automation browser closed by an external process; concurrent navigation from another step; Instagram A/B UI rollouts altering selectors the probe relies on.

Related errors


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