jackwener/OpenCLI · error · CommandExecutionError

Failed to fill Instagram caption

Error message

Failed to fill Instagram caption

What it means

fillCaption evaluates in-page JS that types/sets the caption content into the editor and returns { ok:false } on failure; the library then throws this error. It means the caption text could not be entered into the editor element.

Source

Thrown at clis/instagram/post.js:1168

          const range = document.createRange();
          range.selectNodeContents(editor);
          selection.addRange(range);
        }
        const dt = new DataTransfer();
        dt.setData('text/plain', content);
        editor.dispatchEvent(new ClipboardEvent('paste', {
          clipboardData: dt,
          bubbles: true,
          cancelable: true,
        }));
        return { ok: true, mode: 'contenteditable', value: editor.textContent || '' };
      }

      return { ok: false };
    })(${JSON.stringify(content)})
  `);
    if (!result?.ok) {
        throw new CommandExecutionError('Failed to fill Instagram caption');
    }
}
async function captionMatches(page, content) {
    const result = await page.evaluate(`
    ((content) => {
      const normalized = content.trim();
      const readLexicalText = (node) => {
        if (!node || typeof node !== 'object') return '';
        if (node.type === 'text' && typeof node.text === 'string') return node.text;
        if (!Array.isArray(node.children)) return '';
        if (node.type === 'root') {
          return node.children.map((child) => readLexicalText(child)).join('\\n');
        }
        if (node.type === 'paragraph') {
          return node.children.map((child) => readLexicalText(child)).join('');
        }
        return node.children.map((child) => readLexicalText(child)).join('');
      };

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the post; focus-stealing dropdowns are often transient
  2. Simplify the caption (strip unusual emoji or control characters) to test whether content is the cause
  3. Screenshot the editor state to confirm the caption editor is still open
  4. Update the CLI if the caption-fill script no longer matches the editor element

Example fix

// before
await fillCaption(page, 'Launch day! \u{1F680}\u200D\u{1F4A5} #now'); // ZWJ sequence
// after
await fillCaption(page, 'Launch day! 🚀 #now'); // simpler caption fills cleanly
Defensive patterns

Strategy: try-catch

Validate before calling

if ([...content].length > 2200) throw new Error('Caption exceeds Instagram limit');

Type guard

function isFillableCaption(s) { return typeof s === 'string' && s.trim().length > 0 && [...s].length <= 2200; }

Try / catch

try {
  await fillCaption(page, content);
} catch (e) {
  if (String(e.message).includes('Failed to fill Instagram caption')) {
    await page.evaluate(() => document.activeElement?.blur());
    await page.wait({ time: 1 });
    await fillCaption(page, content);
  } else throw e;
}

Prevention

When it happens

Trigger: The caption-fill page.evaluate returns ok:false — editor element not found, contenteditable not focusable, or the set-value script was rejected by the page.

Common situations: Editor is a contenteditable that rejects direct value assignment, emoji/unicode caption tripping the injection script, an emoji picker or suggestion dropdown stealing focus, or a page navigation mid-fill.

Related errors


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